Skip to content

Commit

Permalink
Database: Fix unsetting latest flag on single snapshot upsert.
Browse files Browse the repository at this point in the history
  • Loading branch information
xsedla1o committed Oct 1, 2024
1 parent a4b3bc9 commit 98c1198
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dp3/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
normal, oversized = self._get_snapshot_state(etype, {eid})
if normal:
try:
self._db[snapshot_col].update_one(
res = self._db[snapshot_col].update_one(
self._snapshot_bucket_eid_filter(eid)
| {"count": {"$lt": self._snapshot_bucket_size}},
{
Expand All @@ -1174,6 +1174,13 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
},
upsert=True,
)

if res.upserted_id is not None:
self._db[snapshot_col].update_many(
self._snapshot_bucket_eid_filter(eid)
| {"latest": True, "count": self._snapshot_bucket_size},
{"$unset": {"latest": 1}},
)
except (WriteError, OperationFailure, DocumentTooLarge) as e:
if e.code != BSON_OBJECT_TOO_LARGE:
raise e
Expand Down Expand Up @@ -1302,7 +1309,7 @@ def save_snapshots(self, etype: str, snapshots: list[dict], ctime: datetime):
for upsert_id in res.upserted_ids.values():
eid = upsert_id.rsplit("_#", maxsplit=1)[0]
unset_latest_updates.append(
UpdateOne(
UpdateMany(
self._snapshot_bucket_eid_filter(eid)
| {"latest": True, "count": self._snapshot_bucket_size},
{"$unset": {"latest": 1}},
Expand Down

0 comments on commit 98c1198

Please sign in to comment.