From bd55da40069decd455ddbdf42bb2cf3e1e5ec61c Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 19 Jul 2026 22:59:37 -0400 Subject: [PATCH] cleanup --- backend/endpoints/saves.py | 15 +++------------ backend/handler/database/saves_handler.py | 6 ------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/backend/endpoints/saves.py b/backend/endpoints/saves.py index ce532f981..989c91f0f 100644 --- a/backend/endpoints/saves.py +++ b/backend/endpoints/saves.py @@ -267,11 +267,7 @@ async def add_save( ) if db_save is None: - # The write above landed on saves_path/actual_filename, whose bytes can - # already belong to a save in another slot (file identity is path+name, - # independent of slot). If that row's recorded hash no longer matches - # what we just wrote, refresh it instead of inserting a duplicate, so it - # does not keep reporting metadata that mismatches the bytes on disk. + # Refresh hash if the file already exists to avoid mismatched metadata. colliding_save = db_save_handler.get_save_by_path( user_id=request.user.id, rom_id=rom.id, @@ -282,10 +278,7 @@ async def add_save( db_save = colliding_save if db_save: - # Track where the bytes actually landed: the file is written under a - # path derived from this request's emulator, which may differ from the - # existing row's location. Persisting file_path/emulator keeps the row's - # hash and its on-disk content from drifting apart. + # Track file path and emulator to prevent hash-content drift. stale_full_path = db_save.full_path update_data: dict = { "file_size_bytes": scanned_save.file_size_bytes, @@ -297,9 +290,7 @@ async def add_save( update_data["slot"] = slot db_save = db_save_handler.update_save(db_save.id, update_data) - # The row moved to a new path, so the previously stored bytes may now - # be orphaned. Slot is not part of the on-disk location, so another - # row can still point at the old path; only unlink it if none do. + # Delete orphaned bytes only if no other row references the old path. if stale_full_path != db_save.full_path: still_referenced = any( other.id != db_save.id and other.full_path == stale_full_path diff --git a/backend/handler/database/saves_handler.py b/backend/handler/database/saves_handler.py index d3da5ccad..739ae7030 100644 --- a/backend/handler/database/saves_handler.py +++ b/backend/handler/database/saves_handler.py @@ -41,9 +41,6 @@ class DBSavesHandler(DBBaseHandler): query = select(Save).filter_by( rom_id=rom_id, user_id=user_id, file_name=file_name ) - # `slot=None` scopes to the null-slot save, not "any slot", so a - # slot-less upload can never match (and overwrite) a save living in a - # named slot. if slot is not None: query = query.filter(Save.slot == slot) else: @@ -59,9 +56,6 @@ class DBSavesHandler(DBBaseHandler): file_name: str, session: Session = None, # type: ignore ) -> Save | None: - # A save's on-disk identity is (file_path, file_name), independent of - # slot. Used to find whichever row owns the bytes an upload is about to - # overwrite. return session.scalars( select(Save) .filter_by(