Add table relation cache for smart album - #4551
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR introduces a per-viewer thumb (cover photo) cache for smart/tag/person albums and keeps it warm by reacting to photo mutations. It also refactors smart-album and relation querying to support an explicit “as seen by user” context for queued recomputation.
Changes:
- Add
album_user_thumbscache table +AlbumUserThumbmodel, and a read-through caching trait used by smart/tag/person albums. - Add a queued recomputation job plus an event listener wired to photo lifecycle/mutation events (tags/persons/rating/highlight).
- Refactor smart albums and tag/person relations to resolve user context consistently (supporting offline/queued recompute).
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| database/migrations/2026_07_21_000000_create_album_user_thumbs_table.php | Adds new cache table for per-viewer album thumbs. |
| app/Models/AlbumUserThumb.php | Introduces model for the cache table and its relations. |
| app/Models/Extensions/CachesAlbumUserThumb.php | Adds read-through thumb caching for albums. |
| app/SmartAlbums/BaseSmartAlbum.php | Adds explicit user context and routes thumb generation through cache. |
| app/SmartAlbums/UnsortedAlbum.php | Uses resolved user context instead of Auth directly. |
| app/SmartAlbums/MyRatedPicturesAlbum.php | Uses resolved user context instead of Auth directly. |
| app/SmartAlbums/MyBestPicturesAlbum.php | Uses resolved user context instead of Auth directly. |
| app/Relations/BaseHasManyPhotos.php | Adds overridable resolved-user logic for non-standard album relations. |
| app/Relations/HasManyPhotosByTag.php | Supports explicit user context for eager constraints. |
| app/Relations/HasManyPhotosByPerson.php | Supports explicit user context for eager constraints. |
| app/Jobs/RecomputeAlbumUserThumbsJob.php | Adds queued recomputation of cached thumbs for already-cached viewers. |
| app/Listeners/RecomputeAlbumUserThumbsOnPhotoChange.php | Dispatches recomputation jobs on relevant photo mutation events. |
| app/Providers/EventServiceProvider.php | Wires new events to the recomputation listener. |
| app/Http/Controllers/Gallery/PhotoController.php | Dispatches new events on tag changes and highlight toggles. |
| app/Http/Controllers/Gallery/AlbumController.php | Dispatches recomputation jobs when tag/person albums’ membership changes. |
| app/Http/Controllers/AiVision/FaceController.php | Dispatches new events when photo-person associations change. |
| app/Events/PhotoTagsChanged.php | New event for tag changes. |
| app/Events/PhotoStarToggled.php | New event for highlight/star toggle. |
| app/Events/PhotoRatingChanged.php | New event for rating changes. |
| app/Events/PhotoPersonsChanged.php | New event for person changes. |
| app/Actions/Photo/Rating.php | Dispatches new rating-changed event. |
| app/Actions/Album/Delete.php | Cleans cache rows when tag/person albums are deleted. |
| app/Models/TagAlbum.php | Routes thumb generation through cache. |
| app/Models/PersonAlbum.php | Routes thumb generation through cache. |
No description provided.