Fix cache listing to include files from new structure
- Update list_all() to scan cache_dir for legacy files directly
(old files stored as CACHE_DIR/{hash}, not CACHE_DIR/legacy/)
- Update cache listing endpoints to use cache_manager.list_all()
instead of iterating CACHE_DIR.iterdir() directly
- This ensures uploaded files appear in the cache UI regardless
of whether they're in the old or new cache structure
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -278,20 +278,39 @@ class L1CacheManager:
|
|||||||
def list_all(self) -> List[CachedFile]:
|
def list_all(self) -> List[CachedFile]:
|
||||||
"""List all cached files."""
|
"""List all cached files."""
|
||||||
files = []
|
files = []
|
||||||
|
seen_hashes = set()
|
||||||
|
|
||||||
|
# New cache structure entries
|
||||||
for entry in self.cache.list_entries():
|
for entry in self.cache.list_entries():
|
||||||
files.append(CachedFile.from_cache_entry(entry))
|
files.append(CachedFile.from_cache_entry(entry))
|
||||||
|
if entry.content_hash:
|
||||||
|
seen_hashes.add(entry.content_hash)
|
||||||
|
|
||||||
# Include legacy files
|
# Legacy files stored directly in cache_dir (old structure)
|
||||||
for f in self.legacy_dir.iterdir():
|
# These are files named by content_hash directly in CACHE_DIR
|
||||||
if f.is_file():
|
for f in self.cache_dir.iterdir():
|
||||||
files.append(CachedFile(
|
# Skip directories and special files
|
||||||
node_id=f.name,
|
if not f.is_file():
|
||||||
content_hash=f.name,
|
continue
|
||||||
path=f,
|
# Skip metadata/auxiliary files
|
||||||
size_bytes=f.stat().st_size,
|
if f.suffix in ('.json', '.mp4'):
|
||||||
node_type="legacy",
|
continue
|
||||||
created_at=f.stat().st_mtime,
|
# Skip if name doesn't look like a hash (64 hex chars)
|
||||||
))
|
if len(f.name) != 64 or not all(c in '0123456789abcdef' for c in f.name):
|
||||||
|
continue
|
||||||
|
# Skip if already seen via new cache
|
||||||
|
if f.name in seen_hashes:
|
||||||
|
continue
|
||||||
|
|
||||||
|
files.append(CachedFile(
|
||||||
|
node_id=f.name,
|
||||||
|
content_hash=f.name,
|
||||||
|
path=f,
|
||||||
|
size_bytes=f.stat().st_size,
|
||||||
|
node_type="legacy",
|
||||||
|
created_at=f.stat().st_mtime,
|
||||||
|
))
|
||||||
|
seen_hashes.add(f.name)
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|||||||
116
server.py
116
server.py
@@ -1348,39 +1348,39 @@ async def list_cache(
|
|||||||
# Get hashes owned by/associated with this user
|
# Get hashes owned by/associated with this user
|
||||||
user_hashes = get_user_cache_hashes(current_user)
|
user_hashes = get_user_cache_hashes(current_user)
|
||||||
|
|
||||||
# Get cache items that belong to the user
|
# Get cache items that belong to the user (from cache_manager)
|
||||||
cache_items = []
|
cache_items = []
|
||||||
if CACHE_DIR.exists():
|
for cached_file in cache_manager.list_all():
|
||||||
for f in CACHE_DIR.iterdir():
|
content_hash = cached_file.content_hash
|
||||||
if f.is_file() and not f.name.endswith('.provenance.json') and not f.name.endswith('.meta.json') and not f.name.endswith('.mp4'):
|
if content_hash not in user_hashes:
|
||||||
if f.name in user_hashes:
|
continue
|
||||||
meta = load_cache_meta(f.name)
|
|
||||||
|
|
||||||
# Apply folder filter
|
meta = load_cache_meta(content_hash)
|
||||||
if folder:
|
|
||||||
item_folder = meta.get("folder", "/")
|
|
||||||
if folder != "/" and not item_folder.startswith(folder):
|
|
||||||
continue
|
|
||||||
if folder == "/" and item_folder != "/":
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Apply collection filter
|
# Apply folder filter
|
||||||
if collection:
|
if folder:
|
||||||
if collection not in meta.get("collections", []):
|
item_folder = meta.get("folder", "/")
|
||||||
continue
|
if folder != "/" and not item_folder.startswith(folder):
|
||||||
|
continue
|
||||||
|
if folder == "/" and item_folder != "/":
|
||||||
|
continue
|
||||||
|
|
||||||
# Apply tag filter
|
# Apply collection filter
|
||||||
if tag:
|
if collection:
|
||||||
if tag not in meta.get("tags", []):
|
if collection not in meta.get("collections", []):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stat = f.stat()
|
# Apply tag filter
|
||||||
cache_items.append({
|
if tag:
|
||||||
"hash": f.name,
|
if tag not in meta.get("tags", []):
|
||||||
"size": stat.st_size,
|
continue
|
||||||
"mtime": stat.st_mtime,
|
|
||||||
"meta": meta
|
cache_items.append({
|
||||||
})
|
"hash": content_hash,
|
||||||
|
"size": cached_file.size_bytes,
|
||||||
|
"mtime": cached_file.created_at,
|
||||||
|
"meta": meta
|
||||||
|
})
|
||||||
|
|
||||||
# Sort by modification time (newest first)
|
# Sort by modification time (newest first)
|
||||||
cache_items.sort(key=lambda x: x["mtime"], reverse=True)
|
cache_items.sort(key=lambda x: x["mtime"], reverse=True)
|
||||||
@@ -1485,7 +1485,7 @@ async def list_cache(
|
|||||||
return HTMLResponse(render_page("Cache", content, current_user, active_tab="cache"))
|
return HTMLResponse(render_page("Cache", content, current_user, active_tab="cache"))
|
||||||
|
|
||||||
# JSON response for APIs - list all hashes with optional pagination
|
# JSON response for APIs - list all hashes with optional pagination
|
||||||
all_hashes = [f.name for f in CACHE_DIR.iterdir() if f.is_file() and not f.name.endswith('.provenance.json') and not f.name.endswith('.meta.json') and not f.name.endswith('.mp4')]
|
all_hashes = [cf.content_hash for cf in cache_manager.list_all()]
|
||||||
total = len(all_hashes)
|
total = len(all_hashes)
|
||||||
start = (page - 1) * limit
|
start = (page - 1) * limit
|
||||||
end = start + limit
|
end = start + limit
|
||||||
@@ -2620,40 +2620,40 @@ async def ui_cache_list(
|
|||||||
# Get hashes owned by/associated with this user
|
# Get hashes owned by/associated with this user
|
||||||
user_hashes = get_user_cache_hashes(current_user)
|
user_hashes = get_user_cache_hashes(current_user)
|
||||||
|
|
||||||
# Get cache items that belong to the user
|
# Get cache items that belong to the user (from cache_manager)
|
||||||
cache_items = []
|
cache_items = []
|
||||||
if CACHE_DIR.exists():
|
for cached_file in cache_manager.list_all():
|
||||||
for f in CACHE_DIR.iterdir():
|
content_hash = cached_file.content_hash
|
||||||
if f.is_file() and not f.name.endswith('.provenance.json') and not f.name.endswith('.meta.json') and not f.name.endswith('.mp4'):
|
if content_hash not in user_hashes:
|
||||||
if f.name in user_hashes:
|
continue
|
||||||
# Load metadata for filtering
|
|
||||||
meta = load_cache_meta(f.name)
|
|
||||||
|
|
||||||
# Apply folder filter
|
# Load metadata for filtering
|
||||||
if folder:
|
meta = load_cache_meta(content_hash)
|
||||||
item_folder = meta.get("folder", "/")
|
|
||||||
if folder != "/" and not item_folder.startswith(folder):
|
|
||||||
continue
|
|
||||||
if folder == "/" and item_folder != "/":
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Apply collection filter
|
# Apply folder filter
|
||||||
if collection:
|
if folder:
|
||||||
if collection not in meta.get("collections", []):
|
item_folder = meta.get("folder", "/")
|
||||||
continue
|
if folder != "/" and not item_folder.startswith(folder):
|
||||||
|
continue
|
||||||
|
if folder == "/" and item_folder != "/":
|
||||||
|
continue
|
||||||
|
|
||||||
# Apply tag filter
|
# Apply collection filter
|
||||||
if tag:
|
if collection:
|
||||||
if tag not in meta.get("tags", []):
|
if collection not in meta.get("collections", []):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stat = f.stat()
|
# Apply tag filter
|
||||||
cache_items.append({
|
if tag:
|
||||||
"hash": f.name,
|
if tag not in meta.get("tags", []):
|
||||||
"size": stat.st_size,
|
continue
|
||||||
"mtime": stat.st_mtime,
|
|
||||||
"meta": meta
|
cache_items.append({
|
||||||
})
|
"hash": content_hash,
|
||||||
|
"size": cached_file.size_bytes,
|
||||||
|
"mtime": cached_file.created_at,
|
||||||
|
"meta": meta
|
||||||
|
})
|
||||||
|
|
||||||
# Sort by modification time (newest first)
|
# Sort by modification time (newest first)
|
||||||
cache_items.sort(key=lambda x: x["mtime"], reverse=True)
|
cache_items.sort(key=lambda x: x["mtime"], reverse=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user