fix(photos): faster large-album loading and album cover lifecycle

Large albums opened slowly and flickered; the default album cover was
also lost in the media-objects refactor.

Large-album loading:
- quantize signed object URLs within a window and send Cache-Control so
  previews are reused instead of re-fetched
- publish photo.updated (not photo.created) when variants are ready, so
  clients update in place without reordering the grid
- worker concurrency + newest-first variant priority; raise default batch

Album cover:
- first uploaded photo becomes the cover when none is set
- clear the cover when the cover photo is trashed or moved out
- "set as album cover" in the photo context menu and actions panel

OpenSpec changes: fix-large-album-load, fix-album-cover
This commit is contained in:
iu
2026-10-11 14:15:59 +03:00
parent 6361e48b20
commit d7a37328f0
40 changed files with 999 additions and 57 deletions
@@ -382,6 +382,18 @@ func testPhotos(t *testing.T, ctx context.Context, r Repos) {
t.Fatalf("cover not set: %+v", al.CoverPhotoID)
}
// Clearing the cover only affects a matching photo id.
r.Photos.ClearCoverIfMatches(ctx, a.ID, newID())
al, _ = r.Albums.GetByID(ctx, a.ID)
if al.CoverPhotoID == nil || *al.CoverPhotoID != p.ID {
t.Fatalf("cover cleared by non-matching id: %+v", al.CoverPhotoID)
}
r.Photos.ClearCoverIfMatches(ctx, a.ID, p.ID)
al, _ = r.Albums.GetByID(ctx, a.ID)
if al.CoverPhotoID != nil {
t.Fatalf("cover not cleared: %+v", al.CoverPhotoID)
}
if err := r.Photos.SetDeleted(ctx, p.ID, true); err != nil {
t.Fatalf("soft delete: %v", err)
}
@@ -524,6 +536,19 @@ func testObjects(t *testing.T, ctx context.Context, r Repos) {
if jobs, _ = r.Photos.ClaimVariantJobs(ctx, 10, time.Minute); contains(jobs, p3.ID) {
t.Fatalf("abandoned job still present: %+v", jobs)
}
// Fresh jobs are prioritized by photo freshness: the newest photo's job is
// claimed first. The delay keeps the two photos' timestamps distinct.
pOlder := seedPhoto(t, ctx, r, owner.ID, a.ID)
time.Sleep(5 * time.Millisecond)
pNewer := seedPhoto(t, ctx, r, owner.ID, a.ID)
order, err := r.Photos.ClaimVariantJobs(ctx, 2, time.Minute)
if err != nil {
t.Fatalf("claim ordered jobs: %v", err)
}
if len(order) < 2 || order[0] != pNewer.ID || order[1] != pOlder.ID {
t.Fatalf("claim order = %+v, want newest first [%s %s]", order, pNewer.ID, pOlder.ID)
}
}
func testSettings(t *testing.T, ctx context.Context, r Repos) {