@@ -1158,7 +1158,7 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
1158
1158
normal , oversized = self ._get_snapshot_state (etype , {eid })
1159
1159
if normal :
1160
1160
try :
1161
- self ._db [snapshot_col ].update_one (
1161
+ res = self ._db [snapshot_col ].update_one (
1162
1162
self ._snapshot_bucket_eid_filter (eid )
1163
1163
| {"count" : {"$lt" : self ._snapshot_bucket_size }},
1164
1164
{
@@ -1174,6 +1174,13 @@ def save_snapshot(self, etype: str, snapshot: dict, ctime: datetime):
1174
1174
},
1175
1175
upsert = True ,
1176
1176
)
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
+ )
1177
1184
except (WriteError , OperationFailure , DocumentTooLarge ) as e :
1178
1185
if e .code != BSON_OBJECT_TOO_LARGE :
1179
1186
raise e
@@ -1302,7 +1309,7 @@ def save_snapshots(self, etype: str, snapshots: list[dict], ctime: datetime):
1302
1309
for upsert_id in res .upserted_ids .values ():
1303
1310
eid = upsert_id .rsplit ("_#" , maxsplit = 1 )[0 ]
1304
1311
unset_latest_updates .append (
1305
- UpdateOne (
1312
+ UpdateMany (
1306
1313
self ._snapshot_bucket_eid_filter (eid )
1307
1314
| {"latest" : True , "count" : self ._snapshot_bucket_size },
1308
1315
{"$unset" : {"latest" : 1 }},
0 commit comments