Skip to content

cache sample rows on disk - #3

Merged
david-whimsical merged 4 commits into
mainfrom
david/sample-cache
May 23, 2026
Merged

david-whimsical merged 4 commits into
mainfrom
david/sample-cache

Conversation

@david-whimsical

Copy link
Copy Markdown
Collaborator

This prevents refetching data in unchanged models, which prevents having a large git diff on wlens generate.


  • adds wlens/.cache/samples to keep track of table's head. Helps us prevent refetching data and large git diffs on wlens generate
  • adds a flag --refresh-samples to force-refresh all cached samples (and table heads)
  • places wlens/cache/sql to wlens/.cache/sql

`wlens generate` used to re-query every table for sample rows on every
run. The rows came back in different order each time (no ORDER BY),
producing hundreds of lines of diff churn, and on big tables the
re-query was just slow.

Now sample rows are written to wlens/.cache/samples/<schema>.<table>.json
on the first run and reused on every subsequent run. The cache is
committed, so teammates and CI share the same pinned rows. We re-fetch
when the table's columns change, when its PII tags change, or when the
obfuscation rules change. `--refresh-samples` forces a re-fetch (pass
no value for all tables, or `=schema.table[,...]` for specific ones).

Existing SQL query cache also moves from wlens/cache/sql/ to
wlens/.cache/sql/ so both caches live under one wlens-internal root.
`wlens init` writes a wlens/.gitignore that keeps the SQL cache out
but tracks the sample cache. `wlens generate` migrates an older
wlens/.gitignore in place.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 79102b8. Configure here.

Comment thread src/wlens/render/markdown.py Resolved
`--refresh-samples` followed by an empty fetch (transient query error
or genuinely-empty table) used to drop the sample-rows section to []
without touching the cache file. Next run would silently put the old
rows back, so the .md flipped between "with rows" and "without rows"
across runs.

Now an empty fetch falls back to the existing cache and logs a warning.
Disk state and the rendered markdown stay in sync.
@david-whimsical
david-whimsical merged commit aca6675 into main May 23, 2026
4 checks passed
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.

1 participant