Fix avatar not refreshing when re-uploaded with same filename

What does this MR do and why?

  • Fix stale avatar display when re-uploading with the same filename
  • Add a ?v=<updated_at_timestamp> cache-busting query parameter to avatar URLs
  • Affects projects, groups, and users — any model using the Avatarable concern

Details

Root cause: Avatar URLs are constructed as /{base_dir}/{model_type}/avatar/{id}/{filename}. When uploading a new avatar with the same filename, the URL is identical, so the browser serves the cached image (5-minute Cache-Control for projects/groups). No ETag or Last-Modified headers are set to help the browser detect content changes.

Fix: Append a version query parameter (?v=<updated_at_timestamp>) to avatar URLs. When the avatar is re-uploaded, the model's updated_at changes, producing a new URL that bypasses the browser cache. Unpersisted objects (without updated_at) get no version parameter, preserving existing behavior. The width parameter is also preserved when present (e.g., ?v=1234567890&width=32).

References

Avatar doesn't get refreshed (#393608 - closed)

How to validate manually

  1. Go to any project's Settings > General
  2. Upload an image as the avatar (e.g., logo.png) and save
  3. Confirm the avatar displays correctly
  4. Prepare a different image but save it with the same filename (logo.png)
  5. Go back to Settings > General, upload this new logo.png as the avatar and save
  6. Before this fix: the old avatar still shows — requires hard refresh to see the new one
  7. After this fix: the new avatar displays immediately without any manual cache clearing

References

Edited by Gloria Odipo

Merge request reports

Loading
Loading