Repository navigation
Conversation
The verify-domain route calls cacheDomainByName on every request. In single-tenant mode resolveDomainFromHost returns the cached copy, so each call reset expiresAt and, under steady traffic, the entry never reloaded from MongoDB. Direct database changes stayed invisible until the app restarted. cacheDomainByName now keeps the expiry of an unexpired entry and only sets a fresh one when the entry is missing or expired. invalidateDomainCache is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The in-memory domain cache (
apps/web/lib/domain-cache.ts) has a 60-second TTL, but under steady traffic the entry never reloads from MongoDB./verify-domaincallscacheDomainByName(domain)on every request (apps/web/app/verify-domain/route.ts). In single-tenant moderesolveDomainFromHostreturnsgetCachedDomain(...), so the domain passed back in is the cached copy, andcacheDomainByNamegives it a freshexpiresAt. As long as requests keep arriving within 60 seconds, the TTL keeps sliding and the cached domain never refreshes.Admin saves are fine because they call
invalidateDomainCache. A change made directly in the database (a migration or a mongosh fix) stays invisible until the app restarts. We hit this on a self-hosted instance: a migration rewrote footer links indomains.sharedWidgets, and the site kept serving the old links for minutes, until a restart.Fix
cacheDomainByNamekeeps the expiry of an existing unexpired entry and sets a fresh one only when the entry is missing or expired.invalidateDomainCacheis unchanged, so an invalidated entry gets a full TTL on its next cache.Tests
apps/web/lib/__tests__/domain-cache.test.tsgains a fake-timer test: an entry that is read and re-cached repeatedly still reloads from the database once the TTL has passed. The existing tests still pass.🤖 Generated with Claude Code