mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
prevent too many image loading at save time
This commit is contained in:
@@ -21,8 +21,17 @@ class CachedImageProvider
|
|||||||
|
|
||||||
final String? cid;
|
final String? cid;
|
||||||
|
|
||||||
|
static int loadingCount = 0;
|
||||||
|
|
||||||
|
static const _kMaxLoadingCount = 8;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
||||||
|
while(loadingCount > _kMaxLoadingCount) {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
loadingCount++;
|
||||||
|
try {
|
||||||
if(url.startsWith("file://")) {
|
if(url.startsWith("file://")) {
|
||||||
var file = File(url.substring(7));
|
var file = File(url.substring(7));
|
||||||
return file.readAsBytes();
|
return file.readAsBytes();
|
||||||
@@ -38,6 +47,10 @@ class CachedImageProvider
|
|||||||
}
|
}
|
||||||
throw "Error: Empty response body.";
|
throw "Error: Empty response body.";
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
loadingCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<CachedImageProvider> obtainKey(ImageConfiguration configuration) {
|
Future<CachedImageProvider> obtainKey(ImageConfiguration configuration) {
|
||||||
|
Reference in New Issue
Block a user