Skip to content

🐛 Fix stale SMTP quota cache on user/alias update and global settings change#1261

Merged
0x46616c6b merged 1 commit intomainfrom
fix/smtp-quota-cache-invalidation
Apr 21, 2026
Merged

🐛 Fix stale SMTP quota cache on user/alias update and global settings change#1261
0x46616c6b merged 1 commit intomainfrom
fix/smtp-quota-cache-invalidation

Conversation

@0x46616c6b
Copy link
Copy Markdown
Member

Summary

The Postfix API endpoint /api/postfix/smtp_quota/{email} could return stale SMTP quota limits for up to 24 hours (cache TTL) in three scenarios:

  1. User quota update: InvalidateUserCacheListener only listened on postPersist, so updating an existing user's smtpQuotaLimits did not invalidate the cache.
  2. Alias quota update: Same issue with InvalidateAliasCacheListener.
  3. Global settings change: The global fallback values (smtp_quota_limit_per_hour/smtp_quota_limit_per_day) were resolved inside the cache callback and baked into the cached result. Changing these settings had no effect until cache expiry.

Fix

  • PostfixController: Move global settings fallback outside the cache callback. The cache now only stores the per-user/alias DB values; the global fallback is applied on every request.
  • InvalidateUserCacheListener / InvalidateAliasCacheListener: Add postUpdate event listener alongside the existing postPersist.

The changes and the PR were generated by OpenCode.

… change

Cache entries for SMTP quotas were not invalidated when:
1. An existing user's or alias's smtpQuotaLimits were updated (only
   postPersist was listened to, not postUpdate)
2. Global smtp_quota_limit_per_hour/per_day settings were changed
   (fallback values were baked into the cached result)

Move the global settings fallback outside the cache callback so it is
evaluated on every request, and add postUpdate listeners to both
entity cache invalidation listeners.

Co-Authored-By: OpenCode <noreply@opencode.ai>
@sonarqubecloud
Copy link
Copy Markdown

@0x46616c6b 0x46616c6b marked this pull request as ready for review April 21, 2026 12:11
@0x46616c6b 0x46616c6b merged commit 77e9261 into main Apr 21, 2026
10 checks passed
@0x46616c6b 0x46616c6b deleted the fix/smtp-quota-cache-invalidation branch April 21, 2026 12:36
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