Browse Source

Fix thumbnail cache key collisions causing wrong images

The cache key was using only src.slice(0, 200) which is not unique —
different base64 images share the same MIME prefix and similar headers.
Now samples from multiple positions (start, middle, end) plus length
to virtually eliminate collisions.

https://claude.ai/code/session_01MvD1n4QeXutgwUpKJuDGHa
handoff-20260429-1057
Claude 4 months ago
parent
commit
3df4089e3d
Failed to extract signature
  1. 8
      src/store/thumbnailCache.ts

8
src/store/thumbnailCache.ts

@ -8,9 +8,11 @@ const cache = new Map<string, string>();
const pending = new Map<string, Promise<string>>();
function cacheKey(src: string): string {
// Use a slice of the data URL that's unique enough to identify the image.
// Skip the "data:image/...;base64," prefix (~30 chars) and take the next 120 chars.
return src.slice(0, 200);
// Sample from multiple positions + length to create a collision-resistant key
// without hashing the entire multi-MB string.
const len = src.length;
const mid = len >>> 1;
return `${len}:${src.slice(30, 90)}:${src.slice(mid, mid + 60)}:${src.slice(-60)}`;
}
export function getThumbnail(src: string): string | undefined {

Loading…
Cancel
Save