mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
prevent too many image loading at save time
This commit is contained in:
@@ -21,22 +21,35 @@ 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 {
|
||||||
if(url.startsWith("file://")) {
|
while(loadingCount > _kMaxLoadingCount) {
|
||||||
var file = File(url.substring(7));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
return file.readAsBytes();
|
|
||||||
}
|
}
|
||||||
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey, cid)) {
|
loadingCount++;
|
||||||
chunkEvents.add(ImageChunkEvent(
|
try {
|
||||||
cumulativeBytesLoaded: progress.currentBytes,
|
if(url.startsWith("file://")) {
|
||||||
expectedTotalBytes: progress.totalBytes,
|
var file = File(url.substring(7));
|
||||||
));
|
return file.readAsBytes();
|
||||||
if(progress.imageBytes != null) {
|
|
||||||
return progress.imageBytes!;
|
|
||||||
}
|
}
|
||||||
|
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey, cid)) {
|
||||||
|
chunkEvents.add(ImageChunkEvent(
|
||||||
|
cumulativeBytesLoaded: progress.currentBytes,
|
||||||
|
expectedTotalBytes: progress.totalBytes,
|
||||||
|
));
|
||||||
|
if(progress.imageBytes != null) {
|
||||||
|
return progress.imageBytes!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw "Error: Empty response body.";
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loadingCount--;
|
||||||
}
|
}
|
||||||
throw "Error: Empty response body.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Reference in New Issue
Block a user