Skip to content

feat: cache machines and load only since last updated - #514

Open
NinaWie wants to merge 8 commits into
mainfrom
cache_machines
Open

NinaWie wants to merge 8 commits into
mainfrom
cache_machines

Conversation

@NinaWie

@NinaWie NinaWie commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Caches machines by saving the latest artworks-collection (all_locations merged with server_locations) to disk

Design choices:

  • Regular reload of last updated machines from the server: Cached machines load immediately. The app requests server changes on launch/foreground at most once every 4 hours, using since argument based on last_updated with a one-day overlap (i.e. loading all changes from yesterday and today).
  • Manual update: There is a new refresh button that triggers the same server-load functionarlity with "since" date
  • Full sync: Runs on first load without a cached snapshot, then every 14 days. When due, the app skips the old cache; after a successful full response, it replaces the in-memory list and cache, removing machines deleted server-side. The existing cache is retained if the request fails.

When we remove the all_locations.json, the app can start without the bundled file and fetch the full dataset from the server. A fresh install will need network access to show machines; existing installs can use their cache.

@jannisborn

Copy link
Copy Markdown
Owner

@NinaWie ready to review?

@NinaWie
NinaWie marked this pull request as ready for review October 4, 2026 10:46
@NinaWie
NinaWie requested a review from jannisborn October 4, 2026 10:46

@jannisborn jannisborn left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, just left a few thoughts

Comment thread PennyMe/Artwork.swift
target: self,
action: #selector(manuallyRefreshServerLocations)
)
navigationItem.rightBarButtonItem?.accessibilityLabel = "Refresh machine data"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we show the time of the last refresh?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea but where? as a pop up when clicking on the refresh button? or a small text underneath (probably ugly)

Comment thread PennyMe/ViewController.swift
query,
get_engine(),
geom_col="geom",
params=params,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a concurrency bottleneck here because we change paradigms: After rollout, we move from a single regular SQL call (to get server_locations.json) to a per-user workload on the DB. If hundreds of users simultanously re-request the whole DB (imagine all users get the udpate at the same point in time), it may OOM even the entire server. Not sure how high this risk is, but it could be worth to @lru_cache the responses. It should also lower latency not only improve conccurrency. Just a thought

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants