prevent too many image loading at save time

This commit is contained in:
2024-11-30 21:30:39 +08:00
parent 9fb3482474
commit 2f4927f719

View File

@@ -21,8 +21,17 @@ class CachedImageProvider
final String? cid;
static int loadingCount = 0;
static const _kMaxLoadingCount = 8;
@override
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
while(loadingCount > _kMaxLoadingCount) {
await Future.delayed(const Duration(milliseconds: 100));
}
loadingCount++;
try {
if(url.startsWith("file://")) {
var file = File(url.substring(7));
return file.readAsBytes();
@@ -38,6 +47,10 @@ class CachedImageProvider
}
throw "Error: Empty response body.";
}
finally {
loadingCount--;
}
}
@override
Future<CachedImageProvider> obtainKey(ImageConfiguration configuration) {