Fix media list duplicates and cache browse link
- Database: Use DISTINCT ON to deduplicate items by content_hash - Database: Count unique content_hashes in count_user_items - Server: Fix media card link from /ui/cache to /cache - Server: Use /raw endpoint for image thumbnails - Server: Add seen_hashes dedup in media list iteration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
16
server.py
16
server.py
@@ -2395,11 +2395,17 @@ async def list_media(
|
||||
|
||||
# Get cache items that belong to the user (from cache_manager)
|
||||
cache_items = []
|
||||
seen_hashes = set() # Deduplicate by content_hash
|
||||
for cached_file in cache_manager.list_all():
|
||||
content_hash = cached_file.content_hash
|
||||
if content_hash not in user_hashes:
|
||||
continue
|
||||
|
||||
# Skip duplicates (same content from multiple runs)
|
||||
if content_hash in seen_hashes:
|
||||
continue
|
||||
seen_hashes.add(content_hash)
|
||||
|
||||
# Skip recipes - they have their own section
|
||||
if cached_file.node_type == "recipe":
|
||||
continue
|
||||
@@ -3812,11 +3818,17 @@ async def ui_media_list(
|
||||
|
||||
# Get cache items that belong to the user (from cache_manager)
|
||||
cache_items = []
|
||||
seen_hashes = set() # Deduplicate by content_hash
|
||||
for cached_file in cache_manager.list_all():
|
||||
content_hash = cached_file.content_hash
|
||||
if content_hash not in user_hashes:
|
||||
continue
|
||||
|
||||
# Skip duplicates (same content from multiple runs)
|
||||
if content_hash in seen_hashes:
|
||||
continue
|
||||
seen_hashes.add(content_hash)
|
||||
|
||||
# Skip recipes - they have their own section
|
||||
if cached_file.node_type == "recipe":
|
||||
continue
|
||||
@@ -3895,7 +3907,7 @@ async def ui_media_list(
|
||||
size_str = f"{size} bytes"
|
||||
|
||||
html_parts.append(f'''
|
||||
<a href="/ui/cache/{content_hash}" class="block">
|
||||
<a href="/cache/{content_hash}" class="block">
|
||||
<div class="bg-dark-700 rounded-lg p-4 hover:bg-dark-600 transition-colors">
|
||||
<div class="flex items-center justify-between gap-2 mb-3">
|
||||
<div class="flex items-center gap-2">
|
||||
@@ -3913,7 +3925,7 @@ async def ui_media_list(
|
||||
video_src = video_src_for_request(content_hash, request)
|
||||
html_parts.append(f'<video src="{video_src}" controls muted loop playsinline class="max-h-32 rounded"></video>')
|
||||
elif media_type == "image":
|
||||
html_parts.append(f'<img src="/cache/{content_hash}" alt="{content_hash[:16]}" class="max-h-32 rounded object-contain">')
|
||||
html_parts.append(f'<img src="/cache/{content_hash}/raw" alt="{content_hash[:16]}" class="max-h-32 rounded object-contain">')
|
||||
else:
|
||||
html_parts.append('<p class="text-gray-400 text-sm py-4">Unknown file type</p>')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user