Cache catalog composite objects on disk for faster startup#425
Merged
Conversation
CatalogBuilder rebuilt the full composite-object list from SQLite on every startup — ~117s of wall time for 151K objects, with ~101s of that hidden behind the deferred background loader. This adds a pickle-based cache at ~/PiFinder_data/cache/catalogs/, written after the background loader finishes and read on subsequent startups. The cache is fingerprinted on the source DB's mtime + size and a CACHE_VERSION constant; user-state `logged` is reset before pickling and re-applied from obs_db on load. On cache hit the background loader is skipped entirely. Also converts ObservationsDatabase.observed_objects_cache from list to set so the per-object check_logged() pass on cache load runs in O(n) rather than O(n*m) — drops the re-apply pass from 3.7s to 275ms. End-to-end startup time on a Pi: 117s -> 10s when the cache is warm. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Everything is loaded synchronously inside build() when the cache is warm, so the UI never sees a "still loading" state and the "Catalogs Fully Loaded" toast is misleading. Only fire the signal when the background loader actually completes deferred work (cache-miss path). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CatalogBuilder's composite-object list at~/PiFinder_data/cache/catalogs/. Written on first run after the background loader finishes, read on subsequent runs to skip both the SQLite walk and the background loader entirely.CACHE_VERSIONconstant.logged(user state) is stripped before pickling and re-applied fromobs_dbon load.ObservationsDatabase.observed_objects_cachefrom list to set so the per-objectcheck_logged()pass after a cache load is O(n) rather than O(n × m).Profiling (on the Pi)
build()returnsWarm-path breakdown: ~7s
pickle.loads(151K dataclass instances), ~1s comet-catalog download, ~1s imports, ~1s grouping/sorting catalogs, ~275ms re-applyinglogged.Test plan
pytest tests/test_catalog_cache.py— 7 tests pass (round-trip, fingerprint mismatch, corrupt pickle, corrupt meta,loggednot persisted, clear, missing-files)CatalogBuilder.build()against the real catalogs DB🤖 Generated with Claude Code