Skip to content

feat(audit-logs): cache request audit log filter facets#3160

Open
bishnubista wants to merge 1 commit into
fosrl:devfrom
bishnubista:feat-cache-audit-log-facets
Open

feat(audit-logs): cache request audit log filter facets#3160
bishnubista wants to merge 1 commit into
fosrl:devfrom
bishnubista:feat-cache-audit-log-facets

Conversation

@bishnubista

@bishnubista bishnubista commented May 26, 2026

Copy link
Copy Markdown
Contributor

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

Followup to #3148. As discussed in that thread, this adds a cache-aside to queryUniqueFilterAttributes so that dashboard refreshes within the same minute don't re-run the six selectDistinct queries that populate the audit log filter dropdowns.

Implementation:

  • Import: regionalCache as cache from #dynamic/lib/cache, matching the dynamic pattern from d1fb2e1.
  • Cache key: cache:audit-log-facets:v1:{orgId}:{timeStartBucket}:{timeEndBucket}, with timestamps bucketed to 60s boundaries so refresh-within-the-minute hits cache. The v1 segment guards against future shape changes.
  • TTL: 60s, per "Lets try 60?" in fix(audit-logs): route request audit log reads through logsDb #3148.
  • Failure isolation: get/set errors are caught and logged via logger.warn; the request never 500s on cache failure.
  • Combined effect: facet dropdowns become approximate to within ~60s. The six underlying queries are unchanged - the prior bench in fix(audit-logs): route request audit log reads through logsDb #3148 showed their current SELECT DISTINCT LIMIT 501 shape already short-circuits via hash dedup with early exit, so a query rewrite would have regressed.

Branch note: this PR is based on dev, so the file still references primaryLogsDb rather than logsDb. #3148's routing fix landed on main; the changes are independent and will compose cleanly when the branches sync.

How to test?

  1. npx tsc --noEmit — no new errors in the changed file (22 pre-existing errors counted before and after).
  2. Manual smoke on an OSS-SQLite stack: load /[orgId]/settings/logs/request in the dashboard, then refresh within 60 seconds. Confirm filter dropdowns populate identically on both requests and that DB query counters don't double. Avoid testing across minute boundaries — bucket rollover would look like a miss.
  3. SaaS verification (optional): with enable_redis: true, confirm cache.getCurrentBackend() returns "redis" for the facet keys.

Wrap queryUniqueFilterAttributes with a cache-aside using the existing #dynamic/lib/cache abstraction (regionalCache as cache, matching d1fb2e1). Cache key includes orgId and timeStart/timeEnd bucketed to 60s boundaries with a v1 version segment. TTL 60s, per Owen's preference in fosrl#3148. Get/set failures warn and fall through; the request never 500s on cache error.

Effect: dashboard refreshes within the same minute hit cache instead of re-running the six selectDistinct queries against requestAuditLog. Facet dropdowns become approximate to within ~60s; the underlying six queries are unchanged.

Followup to fosrl#3148, which routed audit log reads through logsDb for replica routing in SaaS.
@bishnubista

Copy link
Copy Markdown
Contributor Author

@oschwartz10612 Any thoughts?

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