Skip to content

Commit 98c1198

Browse files
committed
Database: Fix unsetting latest flag on single snapshot upsert.
1 parent a4b3bc9 commit 98c1198

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dp3/database/database.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
11581158
normal, oversized = self._get_snapshot_state(etype, {eid})
11591159
if normal:
11601160
try:
1161-
self._db[snapshot_col].update_one(
1161+
res = self._db[snapshot_col].update_one(
11621162
self._snapshot_bucket_eid_filter(eid)
11631163
| {"count": {"$lt": self._snapshot_bucket_size}},
11641164
{
@@ -1174,6 +1174,13 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
11741174
},
11751175
upsert=True,
11761176
)
1177+
1178+
if res.upserted_id is not None:
1179+
self._db[snapshot_col].update_many(
1180+
self._snapshot_bucket_eid_filter(eid)
1181+
| {"latest": True, "count": self._snapshot_bucket_size},
1182+
{"$unset": {"latest": 1}},
1183+
)
11771184
except (WriteError, OperationFailure, DocumentTooLarge) as e:
11781185
if e.code != BSON_OBJECT_TOO_LARGE:
11791186
raise e
@@ -1302,7 +1309,7 @@ def save_snapshots(self, etype: str, snapshots: list[dict], ctime: datetime):
13021309
for upsert_id in res.upserted_ids.values():
13031310
eid = upsert_id.rsplit("_#", maxsplit=1)[0]
13041311
unset_latest_updates.append(
1305-
UpdateOne(
1312+
UpdateMany(
13061313
self._snapshot_bucket_eid_filter(eid)
13071314
| {"latest": True, "count": self._snapshot_bucket_size},
13081315
{"$unset": {"latest": 1}},

0 commit comments

Comments
 (0)