Skip to content

perf(tenants,permissions): single-flight auth cache fills, unknown-subdomain cache, paginated members - #839

Merged
antosubash merged 9 commits into
mainfrom
fix/s14-perf-tenants-caches
Nov 5, 2026
Merged

antosubash merged 9 commits into
mainfrom
fix/s14-perf-tenants-caches

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Performance fix for tenant membership lookups and the members page (local performance review, 2026-11-05).

  • Single-flight cache fills. simple_module_core.singleflight adds SingleFlight, a per-key lock that is dropped when idle, and fill().
    • fill() is an epoch-checked fill. It caches nothing if an invalidation lands during the read. After MAX_FILL_ATTEMPTS (3) it returns the last read uncached, so a request cannot loop.
    • Three caches use it: the tenants memberships cache, the permissions direct-grants cache and the tenant subdomain lookup.
    • Concurrent misses for one user go from N database reads to 1. Measured with 50 concurrent requests:
      • memberships: 50 → 1
      • grants: 50 → 1
      • repeated unknown slug: 50 → 1
  • Unknown subdomains are cached as missing for 5 s.
    • Host invalidations get their own channel, tenants.hosts, keyed by slug or None. tenants.membership carries only user ids.
    • Tenant creation drops only the owner's memberships and the new slug, after commit, on every worker. Before, the review draft cleared every user's cache on each self-service creation.
    • Status changes and deletion still clear everything.
  • Member list pagination uses the repo's Page/paginate/PaginationBar, ordered by (created_at, id), 25 per page (max 200). The page keeps its current page after a mutation, and the members count is computed once per load.
  • Breaking:
    • GET current-members now returns {items, total, page, per_page, pages} instead of an array.
    • TenantService.list_members(tenant_id, params) takes PageParams and returns Page[Membership].
    • TenantService takes invalidate_hosts=; deps.get_tenant_service wires it.
    • All of this is in CHANGELOG and docs/modules/tenants.md.
  • The users session-version cache can adopt fill() in a follow-up. Its files are changed by fix(users): CSRF-protect browser auth requests; logout retires the browser session #832.

Pipeline:

  • /optimize ran once.
  • An automated security check raised two findings, both fixed before review: tenant creation flushed every user's cache, and the fill retries were unbounded.
  • Two review rounds. Pass 1 led to: the separate hosts channel, so a non-UUID subject id such as host:… can no longer be misrouted; one shared fill() helper in place of three copies; a single member count; and the api_tokens test that read the old array.

Local CI: make lint ✓ · make test-py (8 workers) 7890 passed ✓ · make test-js ✓.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-05T17:35:10.405406Z 88fd939 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: d687275
Status: ✅  Deploy successful!
Preview URL: https://528b9325.simple-module-python.pages.dev
Branch Preview URL: https://fix-s14-perf-tenants-caches.simple-module-python.pages.dev

View logs

# Conflicts:
#	CHANGELOG.md
# Conflicts:
#	CHANGELOG.md
@antosubash
antosubash merged commit b1e580e into main Nov 5, 2026
17 checks passed
@antosubash
antosubash deleted the fix/s14-perf-tenants-caches branch November 5, 2026 23:26
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