Skip to content

Commit

Permalink
Cache device only after successful save
Browse files Browse the repository at this point in the history
If saving the device fails, we should keep the old state in the cache and
not the new one.
  • Loading branch information
tsagadar authored and b-rowan committed Sep 24, 2024
1 parent 10bb5dd commit bcbe6ea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion goosebit/updater/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ async def get_device(self) -> Device:
return (await Device.get_or_create(uuid=self.dev_id, defaults={"hardware": hardware}))[0]

async def save_device(self, device: Device, update_fields: list[str]):
await device.save(update_fields=update_fields)

# only update cache after a successful database save
result = await caches.get("default").set(self.dev_id, device, ttl=600)
assert result, "device being cached"
await device.save(update_fields=update_fields)

async def update_force_update(self, force_update: bool) -> None:
device = await self.get_device()
Expand Down

0 comments on commit bcbe6ea

Please sign in to comment.