fix: remove destructive DELETE+INSERT shutdown save that caused progressive data loss

_save_all() in BaseSqliteStore did DELETE FROM table + INSERT all in-memory items
on every shutdown. Since SQLite stores use write-through caching (every CRUD writes
immediately), this was redundant. Worse, if in-memory state had fewer items than
the DB, the DELETE wiped rows and only partial data was reinserted.

- Make _save_all() a no-op (DB is always up to date via write-through)
- Replace self._save() with self._save_item() in 6 seed/default creation methods
- Remove _save_all_stores() shutdown hook (replaced with log-only message)
This commit is contained in:
2026-03-25 13:16:35 +03:00
parent 382a42755d
commit 9a3433a733
8 changed files with 17 additions and 52 deletions

View File

@@ -58,7 +58,7 @@ class GradientStore(BaseSqliteStore[Gradient]):
now = datetime.now(timezone.utc)
for name, tuples in _BUILTIN_DEFS.items():
gid = f"gr_builtin_{name}"
self._items[gid] = Gradient(
gradient = Gradient(
id=gid,
name=name.capitalize(),
stops=_tuples_to_stops(tuples),
@@ -67,7 +67,8 @@ class GradientStore(BaseSqliteStore[Gradient]):
updated_at=now,
description=f"Built-in {name} gradient",
)
self._save()
self._items[gid] = gradient
self._save_item(gid, gradient)
logger.info(f"Seeded {len(_BUILTIN_DEFS)} built-in gradients")
# Aliases