Skip to content

feat(files_external/s3): Harden S3 cache invalidation prefix matching#58638

Open
joshtrichards wants to merge 5 commits intomasterfrom
jtr/refactor-storage-s3-invalidCache
Open

feat(files_external/s3): Harden S3 cache invalidation prefix matching#58638
joshtrichards wants to merge 5 commits intomasterfrom
jtr/refactor-storage-s3-invalidCache

Conversation

@joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Feb 28, 2026

  • Resolves: #

Summary

Refactor invalidateCache() in AmazonS3 (files_external) to improve safety and clarity by:

  • guarding empty prefixes to prevent inadvertent cache wipeouts
  • centralizing prefix invalidation in a helper to remove duplication
  • applying consistent hierarchical key normalization to avoid over-broad prefix matches
  • using exact-or-descendant key matching for hierarchical caches while keeping filesCache exact-key only (non-hierarchical)
  • removing redundant exact-key unsets already covered by invalidation logic

This reduces accidental over-invalidation and makes cache invalidation semantics explicit.

May improve performance by keeping cache hit rates healthier, but unlikely to be dramatic.

TODO

  • Double-check state/coverage of current tests in this area

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

- reuse common logic via new helper
- remove unnecessary duplicate exact key removal (covered by prefix matching logic)
- use str_starts_with over substr
- improve overall clarity (variable naming, consistent ordering of logic)

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Always checks keys for both exact match and a normalized prefix match:

- fixes over-broad prefix matching (e.g. `foo` would match `foobar`)
- normalizes hierarchical keys consistently with rest of class


Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added bug feature: external storage feature: object storage ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) labels Feb 28, 2026
@joshtrichards joshtrichards added this to the Nextcloud 34 milestone Feb 28, 2026
@joshtrichards joshtrichards marked this pull request as ready for review February 28, 2026 04:58
@joshtrichards joshtrichards requested a review from a team as a code owner February 28, 2026 04:58
@joshtrichards joshtrichards requested review from ArtificialOwl, come-nc, leftybournes and salmart-dev and removed request for a team February 28, 2026 04:58
@joshtrichards joshtrichards added the 3. to review Waiting for reviews label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug feature: external storage feature: object storage ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant