feat(NcAvatar): add a version prop for longer avatar caching - #8959
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8959 +/- ##
==========================================
+ Coverage 57.39% 58.27% +0.87%
==========================================
Files 123 123
Lines 4460 4443 -17
Branches 1331 1323 -8
==========================================
+ Hits 2560 2589 +29
+ Misses 1614 1575 -39
+ Partials 286 279 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Does it mean e.g. that for Talk any endpoint that potentially can contain a user information (room, message, attendee, e.t.c) should provide |
No. If a payload has no version the avatar just renders without I'm doing the Talk PR too, and I plan not to add the version endpoint by endpoint there. The current |
Likely rooms list as well, as it's polled every 30 seconds, and always includes all 1-1 rooms - but avatar here could come from another endpoint, not sure if it's cached
That's my concern - if it's something like
This field overhead sent in payload would be ~50MB total Same period - 10K requests to 'avatar/user/size?guestFallback=true' - we assume they cached once per day - I see roughly 2-11 Kb each for 64*64 Not sure, if less pinging of avatars endpoint won't translate to more data transfer as JSON - and whether it's better or worse. |
Fair on the rooms list, I hadn't thought about that 🤔 The 20 bytes is pre-compression though. I mocked a 150-user participants payload: 27 B/user raw, under 4 B/user gzipped, because the key repeats once per user and that's most of the bytes. So ~10MB rather than 50MB, against tens of MB of avatars that get refetched every call since the 1 day window always expires in between. Agreed it shouldn't go everywhere though. I'll keep it to the participants list for now, that's where the huge volume is, and leave chat and rooms alone until there's a reason. wdyt? |
|
Sounds fine, we can discuss it in Talk PR once again with backender POV. One more thing I could think of: NcAvatar uses BrowserStorage to keep keys like
|
Yeah good idea, but the catch is the client only sees that header on a request that actually reaches the server. Once You could keep Happy to go through the idea again on the Talk PR, will open it this evening :) |
| * @param user - The user id | ||
| * @param options - Adjustments for the avatar format | ||
| */ | ||
| export function getAvatarUrl(user: string, options?: AvatarUrlOptions): string { |
There was a problem hiding this comment.
@nextcloud/router provides generateAvatarUrl, which is an exact copy of this. Maybe we migrate to it instead?
I can open a PR, but it would be conflicting. Waiting for opinions. IMO should be beneficial, as function can be reused by apps, and not only locked by NcAvatar
There was a problem hiding this comment.
Went ahead for nc/router repo: nextcloud-libraries/nextcloud-router#916
There was a problem hiding this comment.
Shall we bump @nextcloud/router and get this change in?
export function getAvatarUrl(user: string, options?: AvatarUrlOptions): string {
return generateAvatarUrl(user, {
isDarkTheme: options?.isDarkTheme ?? checkIfDarkTheme(document.body),
isGuestUser: options?.isGuest,
size: options?.size,
guestFallback: true,
version: options?.version,
})
}|
So, is this pr still wanted then ? |
Yes, but I need to update it based on router changes. Will ping when ready |
Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
05eded3 to
f352a0d
Compare
| * @param user - The user id | ||
| * @param options - Adjustments for the avatar format | ||
| */ | ||
| export function getAvatarUrl(user: string, options?: AvatarUrlOptions): string { |
There was a problem hiding this comment.
Shall we bump @nextcloud/router and get this change in?
export function getAvatarUrl(user: string, options?: AvatarUrlOptions): string {
return generateAvatarUrl(user, {
isDarkTheme: options?.isDarkTheme ?? checkIfDarkTheme(document.body),
isGuestUser: options?.isGuest,
size: options?.size,
guestFallback: true,
version: options?.version,
})
}Drops the duplicated URL construction now that @nextcloud/router 3.2.0 supports guestFallback and version. Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>

Adds a
versionprop toNcAvatar. When set it goes into the avatar URL as?v=, which earns a much longer cache lifetime server-side. Talk will pass it from the participant list.Also fixes the existing current-user handling. The version was appended as
'?v=' + versiononto a URL that already ends in?guestFallback=true, giving/avatar/me/64?guestFallback=true?v=3. PHP reads that asguestFallback=true?v=3with novparameter, so cache-busting your own avatar has never worked. Going throughgenerateUrlgives a proper&v=.Needs nextcloud/server#64295 to have any effect. Harmless without it.
☑️ Resolves
🖼️ Screenshots
Nothing visual. The avatar renders the same, only the URL changes.
🏁 Checklist
stable8for maintained Vue 2 version or not applicable