Fix cache-issues due to hash collisions
This commit is contained in:
parent
45611be9b2
commit
36467b6673
5 changed files with 13 additions and 11 deletions
12
lib/core/cache/image_cache.dart
vendored
12
lib/core/cache/image_cache.dart
vendored
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ class _GalleryState extends State<Gallery> {
|
|||
: null,
|
||||
),
|
||||
child: Hero(
|
||||
tag: file.heroTag(),
|
||||
tag: file.tag(),
|
||||
child: ThumbnailWidget(file),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -58,7 +58,7 @@ class _VideoWidgetState extends State<VideoWidget> {
|
|||
? _getVideoPlayer()
|
||||
: _getLoadingWidget();
|
||||
return Hero(
|
||||
tag: widget.file.heroTag(),
|
||||
tag: widget.file.tag(),
|
||||
child: content,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue