mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:42:59 +03:00
🐛 Bug Report: Default profile picture is not cached #281
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ItalyPaleAle on GitHub.
Originally assigned to: @kmendell on GitHub.
Reproduction steps
When invoking
GET /api/users/{id}/profile-picture.png, if the user doesn't have a profile picture, the default one is generated.However, the image is generated on every request, and this is a costly operation.
Expected behavior
The default profile picture should be cached. Ideally, it's created once when the user is created (or when another picture is deleted).
Actual Behavior
The image is generated on every request, and this is a costly operation.
Version and Environment
Current main branch
Log Output
No response
@stonith404 commented on GitHub:
Yeah caching the profile picture probably would make sense. What it makes a bit difficult is that the profile picture needs to be updated when the name of a user changes.
We probably would have to add a column in the database to mark if a user has uploaded a custom profile picture. If not, the profile picture needs to be updated on every name change.
@kmendell commented on GitHub:
I like that approach but i think it may need some tweaking, to make it not overly engineered/complicated.
@ItalyPaleAle commented on GitHub:
There could be another way.
Every time a user is created, or there's a name change, generate the default profile image and store it in a separate folder (or instead of giving it the name of the UUID of the user, name it after the initials, such as "es.png"). We can optionally skip doing that if the user has a personal profile pic (but this isn't strictly necessary). If the image already exists (e.g. there's already "es.png" either because of Elias S. or because of Emanuela S.), you can skip re-generating this (this will need some coordination with locks etc to make sure we aren't generating the same image twice in parallel).
Those images are never deleted. Even if people change names, they can be kept around, so when another user with the same initials appear, the image already exists. This means that there may be a bit of waste, but it's negligible (in the absolute worst case, very unlikely in the real world, where you go AA..AB..AC..ZZ, you get 676 images, which is a relatively small number).
@ItalyPaleAle commented on GitHub:
Not a super-high priority, but creating this to make sure I don't forget about it either.