fix: delete stale cached albums that no longer exist in VK
After refresh_vk_catalog syncs the album list from VK, remove any VkCachedAlbum rows whose album_id was not returned by the API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,16 @@ def _sync_user(db, user_id: int, token: str, group_id: str) -> None:
|
||||
count=a.get("count"),
|
||||
fetched_at=now,
|
||||
))
|
||||
# Delete cached albums that no longer exist in VK
|
||||
(
|
||||
db.query(VkCachedAlbum)
|
||||
.filter(
|
||||
VkCachedAlbum.user_id == user_id,
|
||||
VkCachedAlbum.vk_group_id == group_id,
|
||||
VkCachedAlbum.album_id.notin_(album_ids),
|
||||
)
|
||||
.delete(synchronize_session=False)
|
||||
)
|
||||
db.flush()
|
||||
|
||||
# ── products (extended=1 gives albums_ids per product) ───────────────────
|
||||
|
||||
Reference in New Issue
Block a user