fix(dav): make contact photo cache max-age configurable#59551
fix(dav): make contact photo cache max-age configurable#59551arndttouby wants to merge 6 commits intonextcloud:masterfrom
Conversation
The ImageExportPlugin sets Cache-Control: max-age=3600 before the try/catch block, which means 204 No Content responses (no photo found) are also cached by the browser for 1 hour. If a photo is added to a contact after the initial request, the browser serves the cached empty response and the photo remains invisible until the cache expires. Move Cache-Control and ETag headers inside the try block so they are only set for 200 OK responses (photo found). For 204 responses, set Cache-Control: no-cache, no-store, must-revalidate so the browser always re-checks on the next request. Signed-off-by: Arndt Touby <arndt@touby.eu>
|
Hi @arndttouby Thank you for taking the time to create this PR. |
|
So the code looks good. But there is a down side to this change and probably why the code was originally written the way it was. Yes the changes you made address one specific scenario, when a user adds a photo, the photo might not show for an hour. But the changes now causes the client to continuously make requests for photos that don't exist every time the page loads, this would cause 1000's of unneeded requests on some systems, that access the database to check if there is a photo. I think the trade off, of the one hour delay vs the performance impact of the changes you are suggesting is worth it. |
Replace hardcoded max-age=3600 with a configurable app value 'contact_photo_cache_max_age' (default: 3600). Signed-off-by: Arndt Touby <arndt@touby.eu>
Replace hardcoded max-age=3600 with a configurable app value 'contact_photo_cache_max_age' (default: 3600). Add IConfig injection and unit tests for custom and zero max-age values. Signed-off-by: Arndt Touby <arndt@touby.eu>
|
Hi @SebastianKrupinski, thanks for the thorough review — your concern about the performance impact is absolutely valid. I've reworked the approach based on your feedback. Instead of moving the $maxAge = $this->config->getAppValue('dav', 'contact_photo_cache_max_age', '3600');Key points:
This way, the one-hour default stays in place for large installations, but smaller setups or admins who need faster photo updates have a knob to turn. |
…r.php Signed-off-by: Arndt Touby <arndt@touby.eu>
Ensures the Cache-Control max-age value is always numeric, preventing potential header injection via malformed config values. Signed-off-by: Arndt Touby <arndt@touby.eu>
Summary
Make the
Cache-Control: max-agevalue for contact photo exports configurable via the app config keydav.contact_photo_cache_max_age(default:3600).This addresses the concern raised in the initial review: removing caching for
204 No Contentresponses would cause unnecessary database lookups on large installations. Instead, the default behavior is preserved (1 hour cache), but administrators can tune the value as needed — including setting it to0for development or debugging.Changes
ImageExportPlugin.php: InjectIConfig, readcontact_photo_cache_max_ageapp value (default3600), use it in theCache-Controlheader instead of a hardcoded value.Server.php: PassIConfigas second argument toImageExportPluginconstructor.ImageExportPluginTest.php: AddIConfigmock to existing tests, add two new test cases (testCardWithCustomMaxAgewith 120s,testCardWithZeroMaxAgewith 0s).Usage
Checklist