"UPDATE managed_cloud_uploads SET confirmed_at=? WHERE operation_id=?",
(datetime.now(UTC).isoformat(),operation_id),
)
self.checked=0.0
defretained(self,row):
meta=self.db.one(
"SELECT starred FROM asset_metadata WHERE asset_id=?",(row["asset_id"],)
)
ifmetaandmeta["starred"]:
head=self.db.one(
"SELECT image_id FROM managed_cloud_uploads WHERE device_id=? AND asset_id=? AND confirmed_at IS NOT NULL ORDER BY uploaded_at DESC,image_id DESC LIMIT 1",
(row["device_id"],row["asset_id"]),
)
ifnotheadorhead["image_id"]==row["image_id"]:
returnTrue
ifrow["job_id"]:
head=self.db.one(
"SELECT image_id FROM managed_cloud_uploads WHERE device_id=? AND job_id=? AND confirmed_at IS NOT NULL ORDER BY uploaded_at DESC,image_id DESC LIMIT 1",
(row["device_id"],row["job_id"]),
)
ifheadandhead["image_id"]==row["image_id"]:
returnTrue
returnFalse
defeligible(self,device_id,image_id):
row=self.db.one(
"SELECT * FROM managed_cloud_uploads WHERE device_id=? AND image_id=?",
(device_id,image_id),
)
ifnotroworself.retained(row):
returnFalse
# A confirmed replacement is mandatory; failed/unknown uploads cannot
# evict the last known usable cloud image.
newer=self.db.one(
"SELECT image_id FROM managed_cloud_uploads WHERE device_id=? AND confirmed_at IS NOT NULL AND uploaded_at>? LIMIT 1",
(device_id,row["uploaded_at"]),
)
ifnotnewer:
returnFalse
state=self.service.state(device_id)
ifstate["base_image_id"]==image_id:
returnFalse
ifself.db.one(
"SELECT id FROM overrides WHERE device_id=? AND image_id=?",
(device_id,image_id),
):
returnFalse
forrinself.db.all(
"SELECT payload FROM playlists UNION ALL SELECT payload FROM jobs"