Fix cache-issues due to hash collisions

This commit is contained in:
Vishnu Mohandas 2020-06-24 01:43:45 +05:30
parent 45611be9b2
commit 36467b6673
5 changed files with 13 additions and 11 deletions

View file

@ -5,25 +5,25 @@ import 'package:photos/core/cache/lru_map.dart';
import 'package:photos/models/file.dart';
class FileLruCache {
static LRUMap<int, dart.File> _map = LRUMap(25);
static LRUMap<String, dart.File> _map = LRUMap(25);
static dart.File get(File file) {
return _map.get(file.hashCode);
return _map.get(file.tag());
}
static void put(File file, dart.File imageData) {
_map.put(file.hashCode, imageData);
_map.put(file.tag(), imageData);
}
}
class BytesLruCache {
static LRUMap<int, Uint8List> _map = LRUMap(25);
static LRUMap<String, Uint8List> _map = LRUMap(25);
static Uint8List get(File file) {
return _map.get(file.hashCode);
return _map.get(file.tag());
}
static void put(File file, Uint8List imageData) {
_map.put(file.hashCode, imageData);
_map.put(file.tag(), imageData);
}
}

View file

@ -129,10 +129,12 @@ class File {
return generatedId.hashCode ^ uploadedFileId.hashCode ^ localId.hashCode;
}
String heroTag() {
String tag() {
return "local_" +
localId.toString() +
":remote_" +
uploadedFileId.toString();
uploadedFileId.toString() +
":generated_" +
generatedId.toString();
}
}

View file

@ -176,7 +176,7 @@ class _GalleryState extends State<Gallery> {
: null,
),
child: Hero(
tag: file.heroTag(),
tag: file.tag(),
child: ThumbnailWidget(file),
),
),

View file

@ -58,7 +58,7 @@ class _VideoWidgetState extends State<VideoWidget> {
? _getVideoPlayer()
: _getLoadingWidget();
return Hero(
tag: widget.file.heroTag(),
tag: widget.file.tag(),
child: content,
);
}

View file

@ -59,7 +59,7 @@ class _ZoomableImageState extends State<ZoomableImage>
minScale: PhotoViewComputedScale.contained,
gaplessPlayback: true,
heroAttributes: PhotoViewHeroAttributes(
tag: widget.photo.heroTag(),
tag: widget.photo.tag(),
),
);
} else {