This commit is contained in:
mike
2026-06-28 02:29:31 +02:00
parent 3f91694491
commit 6ad11fc6c0
2 changed files with 122 additions and 28 deletions

View File

@@ -307,6 +307,8 @@ def _idle_turntable_daemon():
fname, group_id, sort_order = row[0], row[2], row[6]
if not group_id:
continue
if fname.startswith("_turntable/"):
continue
if group_id not in groups:
groups[group_id] = (fname, sort_order)
else:
@@ -1378,24 +1380,73 @@ def _write_turntable_static() -> None:
except Exception:
group_names = {}
# Preferred filename per group (sort_order=0)
preferred: dict = {}
# Fetch active and existing group IDs and filenames from the database (excluding turntable assets)
all_db_gids = set()
active_db_gids = set()
all_db_filenames = set()
active_db_filenames = set()
try:
for row in database.list_persons():
fname, gid, sort_order = row[0], row[2], row[6]
if not gid:
continue
if gid not in preferred:
preferred[gid] = (fname, sort_order)
else:
cur = preferred[gid][1]
if sort_order is not None and (cur is None or sort_order < cur):
preferred[gid] = (fname, sort_order)
except Exception:
pass
conn = database.get_db_connection()
cur = conn.cursor()
cur.execute("""
SELECT filename, group_id, archived, hidden
FROM person
WHERE NOT (filename LIKE '_turntable/%')
""")
for fname, gid, archived, hidden in cur.fetchall():
is_archived = bool(archived) if archived is not None else False
is_hidden = bool(hidden) if hidden is not None else False
all_db_filenames.add(fname)
if not is_archived and not is_hidden:
active_db_filenames.add(fname)
if gid:
all_db_gids.add(gid)
if not is_archived and not is_hidden:
active_db_gids.add(gid)
cur.close()
database._put_db_connection(conn)
except Exception as db_err:
print(f"[static] DB check error: {db_err}")
turntables = []
for gid in tc.list_cached_group_ids(output_dir):
is_orphaned = False
is_active = False
if gid.startswith("file_"):
fname = gid[5:]
if all_db_filenames and fname not in all_db_filenames:
is_orphaned = True
elif active_db_filenames and fname in active_db_filenames:
is_active = True
else:
if all_db_gids and gid not in all_db_gids:
is_orphaned = True
elif active_db_gids and gid in active_db_gids:
is_active = True
# 1. Truly orphaned turntable caches (no associated base images or files in DB)
if is_orphaned:
print(f"[static] Deleting truly orphaned turntable cache and DB records for group/file {gid}")
tc.delete_state(output_dir, gid)
try:
conn = database.get_db_connection()
cur = conn.cursor()
cur.execute("DELETE FROM person WHERE group_id = %s", (gid,))
conn.commit()
cur.close()
database._put_db_connection(conn)
except Exception as del_err:
print(f"[static] Failed to clean DB records for orphaned group/file {gid}: {del_err}")
continue
# 2. Inactive turntable caches (associated group/file is fully archived or hidden)
if not is_active:
# Keep cache on disk but do not write to turntables.json (hide from UI)
continue
state = tc.load_state(output_dir, gid)
if not state:
continue