Skip to content

Add tag filtering to Cache.iterkeys - #372

Open
Gonghan-Princess wants to merge 1 commit into
grantjenks:masterfrom
Gonghan-Princess:codex/feat-iterkeys-tag-filter
Open

Gonghan-Princess wants to merge 1 commit into
grantjenks:masterfrom
Gonghan-Princess:codex/feat-iterkeys-tag-filter

Conversation

@Gonghan-Princess

Copy link
Copy Markdown

Retrieving keys by tag currently requires iterating every key and reading each cached value and tag. Add an optional tag argument to Cache.iterkeys so SQLite filters keys before pagination, without fetching cached values.

cache.iterkeys(tag='counter') returns matching keys in the existing database sort order; reverse=True reverses that order. Omitting tag preserves iteration over all keys, while tag=None selects untagged keys. Empty and numeric tags remain valid. Iteration still includes expired entries. The existing tag index can be used for non-None tag filters; no schema change is required.

Fixes #341.

Validation on Windows / Python 3.12.10:

  • Before implementation, all 22 new cases failed because tag was unsupported; the existing empty-cache test passed.
  • Full suite: pytest -n 4 — 273 passed, 99.27% coverage (98% required), including the tutorial examples.
  • Final focused suite: 23 passed, covering tag values, omitted arguments, no matches, ascending and descending pagination across mixed key types, identical stored keys distinguished by raw, tag indexes, expired entries, and no value fetches.
  • Blue, Flake8, isort, mypy, Pylint 2.17.7, rstcheck, and Sphinx HTML build passed. Doc8 passed on an LF-normalized docs export; the Windows checkout's CRLF line endings trigger its carriage-return check. No lint rules were disabled.
  • Independent automated review also passed 40 comparisons with direct SQL over 1,000 mixed keys, nine tag values, both directions, and enabled/disabled tag indexes.
  • Other Python versions and Linux/macOS remain for CI.

AI assistance: OpenAI Codex prepared the implementation, tests, documentation, and PR text. A separate Codex agent reviewed the patch; no human review is claimed.

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.

Unable to efficiently retrieve keys by tag

1 participant