feat(corpus): cache the metadata tables by sha256 between sessions (#64)
R/cache.R was a stub, so a remote session read the ten metadata tables (about 3 MB) over HTTP every time. cog_open() now keeps them in USCOGDATA_CACHE_DIR/corpus/ and points the metadata views there. A cached file is used only while its sha256 matches the session's manifest; a download is checked before it replaces anything. Any failure (an HTTP error such as Hugging Face's 429, a mismatch, an unwritable directory) falls back to remote reads with a message. A local corpus is read in place and never cached. The yearly partitions stay remote; cog_mirror() is still the tool for repeat work on them. Against the public corpus, 2026-11-12, one run each, fresh cache: session open 1.76 s cold -> 0.38 s warm first query 1.16 s cold -> 0.68 s warm cog_spending() for Madison (552025209777), 2012 and 2020, returns the same 46 rows and the same digest as main. Live-corpus tests pass. Closes #64 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+238
-11
No files matched your search
@@ -1,5 +1,22 @@
|
||||
# uscogdata (development version)
|
||||
|
||||
## Faster sessions on the remote corpus
|
||||
|
||||
Opening a session against the public corpus took about 5.6 seconds. It now takes
|
||||
about 1.8 seconds the first time and about 0.4 seconds after that (measured
|
||||
2026-11-12, one run each). Two changes do it:
|
||||
|
||||
- A session keeps the HTTP file details it has already requested instead of asking
|
||||
again for every view and query. A repeated query in the same session drops from
|
||||
about 0.55 seconds to 0.02.
|
||||
- The ten metadata tables, about 3 MB, are kept in `USCOGDATA_CACHE_DIR` and used
|
||||
only while their SHA-256 matches the manifest. A republished corpus is picked up
|
||||
when the manifest is, and if a download fails or does not match, the session reads
|
||||
the tables remotely as before.
|
||||
|
||||
The yearly data files are still read remotely. For repeat work on them,
|
||||
`cog_mirror()` remains the fastest option. Results are unchanged.
|
||||
|
||||
## Fiscal-year periods for each row
|
||||
|
||||
`year` is the Census survey year, and a survey year covers different months for
|
||||
|
||||
Reference in new issue
Block a user