Skip to content

LR-LIB-FOLDER: albums.list counts a folder from the counts the sidebar keeps (stacked on #768 and #3387) - #3395

Open
nledford wants to merge 21 commits into
storytold:mainfrom
nledford:perf-folder-counts
Open

nledford wants to merge 21 commits into
storytold:mainfrom
nledford:perf-folder-counts

Conversation

@nledford

@nledford nledford commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #768 and #3387. Stacked on #768 and #3387 (a merge of their heads c12dec194b67c3ff7d62ef42f94b21ca6e7de6ef and 9de93772a5f34ebe2c63f018bbfa1d514fe51944; #3387 is stacked on #2020): this PR's own commit is the last one, LR-LIB-FOLDER: albums.list counts a folder from the counts the sidebar keeps. #768 and #3387 were both opened against main and neither contains the other, so the merge commit is the base.

Problem

In #768 a folder of albums holds the photos of the albums inside it, and albums.list reports each folder's count by Catalog::album_count, a pass over every photo for each folder. #3387 moves the smart albums' counts off the UI thread, but a library with many folders still freezes on albums.list: in a library of 844,425 photos with 176 albums (85 of them folders), albums.list took about 50 s with #3387 alone, with the window unresponsive for that long, all of it the folder counts.

Change

  • AlbumTally (the counts the sidebar keeps, LR-LIB-SMARTALBUM: creating or giving a keyword no longer freezes the window while albums are counted #2020) counts folders too, from the albums inside them and with no pass of their own: the smart albums' kept photos are OR-ed together, the photos chosen for the other albums are added, deleted photos are left out. A folder's kept photos follow an edit to a few photos like a smart album's (the touched photos are asked of the albums inside the folder, not of every album again).
  • albums.list takes a folder's count from the kept counts, and reports countPending on it, as for a smart album (a folder is behind with the counts; when only the clock moved, a folder is behind only if an album inside it asks about "the last N days"). Documented in docs/control-protocol.md, docs/mcp.md and docs/whats-new.md.
  • The sidebar still shows no count on a folder row.

Not in this PR: a folder's kept photos start as a hash set when the first album absorbed into it is one (photo ids over 65,535 do that in a large library); the memory is in proportion to the photos held, as for the albums', measured below. A folder holding a loop or a chain deeper than the depth limit has no test of its own (the counts equal album_count through the shared code path, read by two reviewers).

How it was checked

Timings (albums.list over the control channel, alone in the app, a second connection pinging activity.list meanwhile; fresh APFS clone of a library copy of 844,425 photos with 176 albums, 85 of them folders and 91 smart, backups off, catalog format 11; 3 paired runs each, base and branch alternating, a small script of mine over the control channel (the maintainer's tooling was not used); the app of the person who ran them was open during the runs; every run started with the 1-minute load average between 7 and 36, none above 40; 6 pairs: runs 1–3 with the rating step failing in my driver, runs 4–6 with it fixed). The measurement base is e423a99eea (the catalog format 11 chain, #768 and #2020) plus #3387's commit; the branch is that plus this commit, cherry-picked in a throwaway branch:

base: e423a99eea + #3387 + this commit
albums.list, first answer 48.3–50.0 s 0.045–0.054 s
longest gap between pings while it ran 5.06–5.68 s (their limit) 0.050–0.108 s
asked again 49.5–51 s, or no answer in 60 s 0.027–0.046 s
asked after rating one photo 49–52 s, or no answer in 60 s 0.028–0.039 s
counts current (smart albums and folders) after 98–100 s 26.6–28.5 s (the worker)
sum of the folders' counts once current 4,336,046 4,336,046 (the same)

The folders' counts are the same photo for photo as the full pass gives, for the library copy; the rest of the equality is the 900-edit comparison in view_follow.rs.

Merging

Checklist

  • No new panic path in non-test code: no unwrap / expect / panic!, no indexing or unchecked arithmetic on a number from a file, a person or an agent (get, checked_mul, NaN and char boundaries handled)
  • New text on screen goes through tr() and has its key in crates/ui-egui/locales/*.json; a new shortcut is free in docs/library-shortcuts.md (no text on screen)
  • The feature's rows in docs/parity-checklist.md and its entry in docs/gaps.md are updated, honestly (🟡 when it is partial), in the same commit
  • New code has a caller: no command, module or setting that nothing reaches yet
  • Every new image, icon or other asset has its entry in assets/ATTRIBUTION.md; no font or media files added
  • Ready to merge (otherwise open it as a draft)

Summary by CodeRabbit

  • New Features
    • Folders can be selected as photo sources, showing photos from their nested albums without duplicates. Folder counts are available alongside smart-album counts.
    • Album lists can show existing counts while updated totals are calculated, with an indicator when counts may be out of date.
  • Bug Fixes
    • Prevented smart-album rules and album moves that would create folder loops.
    • Improved count updates after photo, rule, and time-based changes, and keyword-list changes now refresh related views.

nledford and others added 21 commits October 28, 2026 07:11
… window while albums are counted

In a large library with smart albums, the frame after an edit the album
tally could not follow photo by photo counted every smart album over
every photo on the UI thread: seconds, during which the window froze.
Creating a keyword inside another one (and giving it to the selected
photos) was such an edit, because Op::SetKeyword was classed as a broad
op, so the view, the folder tree and the date groups were worked out
again too.

- The keyword list changes no photo and no rule, filter or sort reads
  it: Op::SetKeyword now records Aspects::KEYWORD_LIST instead of
  marking the catalog's change memory broad. The view and the albums'
  counts follow the edit from the photos it touched; only the keyword
  tree is made again.
- A count of every photo that is still needed (an album's rules or
  photos changed, an edit to more than 256 photos, a new minute with an
  "in the last…" rule, a library opened) runs on a worker thread over a
  copy of the catalog. The sidebar keeps the counts it showed (none
  before the first count, and none of another library) and follows the
  edits made meanwhile once the count is in. AlbumTally::update only
  follows now; the caller decides where to count whole.

Co-Authored-By: Claude <noreply@anthropic.com>
…de it

Catalog::album_contains / album_photos / album_count answer for a folder: the
photos of the albums and smart albums inside it at any depth, each once, deleted
ones left out. Catalog::album_members names those albums. A query over a folder
gathers its photos once (FolderPhotos), not per photo and album.

album_reaches follows folders, so a smart album limited to the folder it is in
is reported as a loop; evaluation was already guarded. albums_of still names
albums only. Parents that form a ring in a damaged library end the search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
library.source {kind: album, id} takes a folder too: the grid shows the photos
of every album and smart album inside it, each once, under the folder's name,
following the sort and the filter. A folder has no order by hand, so the
album's own-order pass leaves it alone (it would have turned newest-first
round). album.removePhotos refuses a folder instead of recording an empty step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The folder row in the sidebar's Albums section is a source, as a collection
set is in Lightroom Classic: a click fills the grid with the photos of the
albums inside it and marks the row; folding is the triangle's alone. Folder
rows carry no count, and the sidebar's count cache skips them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parity row and What's new: a folder shows the photos of the albums inside it;
only the triangle folds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne answer for damaged folders

A pass over the library (query, people_in, album_count, album_photos) gathers
each folder of albums it asks about once, so a smart album limited to a folder
costs what the folder does (it asked every album's list for every photo).
Replaces the query-only Prepared.

smart_album_would_loop_in: whether rules lead to the folder an album is about
to go in. A folder that also has rules is a folder to every question, and an
album inside a plain album is not in the folder around them (damaged files).

The speed test now measures against asking one photo at a time, with photos
in no album, rather than against the clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Op::MoveAlbum's walk up the parents for the no-cycle check never ended when the
parents already formed a ring (a damaged library file). Bounded by the number
of albums; regression test moves an album into such a ring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r it shows

Review fix. Showing a folder made its own New ▸ Create Smart Album from Filter…
save a view limited to that folder inside it: an album that includes itself,
reported only afterwards. album.createSmart, album.move and album.reorder now
refuse that (also for a smart album inside a folder being moved) and say where
it can go. album.setCover refuses a folder. The reopen test's scratch folder
goes away however the test ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bar test proves the triangle alone folds

Review fix. The test clicked the triangle only while the folder was already
shown, so it couldn't tell a fold from a click on the row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
album_move_would_loop names the smart album a move would make include itself
(one question for the engine and the sidebar). A pass keeps the folders it
gathered apart by catalog as well as id. The speed test takes the best of five
runs against a 5x margin: one run against 10x failed 2 times in 40 on a
machine with 30 busy loops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… it shows

album.setRules with replace (what the rules dialog sends) started from an
empty filter and kept only the library folder, so a folder's view saved as a
smart album matched the whole library after OK. It keeps the album field too,
unless the call gives album: null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rt album that shows it

The folder was outlined as a place to drop, then the drop was refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nts gathers

Review fixes:
- a folder of albums has no order of its own, so it no longer counts as an album in its own order: a small edit is followed photo by photo instead of the view being worked out whole
- the test that a folder of big albums is gathered in one pass counts the gathers instead of comparing wall-clock timings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ves out a folder that has rules

After the rebase onto the tally of storytold#2422: a folder that a library file also gives rules was counted again and took part in the chain heights, and a loop through a folder (a smart album limited to it, one inside it that tests the first) was missed, so the whole count gave one of them a different number than counting it alone. The folder's number for agents (albums.list) is counted on its own, as the whole count leaves folders out.
…smart albums inside it

A folder of albums that holds a smart album with an in-the-last-days rule shows different photos once the minute passes, but the view and the count only noticed the rules of the albums a source tests, not those of a folder's members, so they stayed stale until an edit. The check now goes through the folder's albums at any depth.
…debar keeps

`albums.list` counted every smart album's photos on the UI thread (`AlbumTally::of`) before it answered: with 176
albums in a library of 844,425 photos the window did not respond for about 79 s.

In the app the command now answers from the counts the sidebar keeps (counted on the `lc-album-counts` worker,
followed through edits to a photo or a few): an album of chosen photos is counted from its list, a smart album's count
is the kept one, and `countPending: true` says it is not of the catalog as it is now yet (the count made before, or 0).
A session with no window (the CLI, the headless MCP server) counts once, keeps the counts and follows edits.
# Conflicts:
#	crates/engine/src/cmd/query.rs
#	crates/engine/src/tests.rs
#	docs/parity-checklist.md
…r keeps

A folder's count in `albums.list` (the photos of the albums inside it) was a pass over the whole library for each
folder on the UI thread: with 85 folders in a library of 844,425 photos, about 50 s in which the window did not
respond, even with the smart albums' counts kept off the UI thread.

`AlbumTally` now counts a folder too, by putting together the photos of the albums inside it (the smart albums'
photos it already keeps, the photos chosen for the others), and follows edits to a few photos in folders as it does in
smart albums. `albums.list` takes a folder's `count` from the kept counts and marks it `countPending` with them.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5194cc2 and e048d41.

Files selected for processing: 28
  • crates/catalog/src/lib.rs
  • crates/catalog/src/query.rs
  • crates/catalog/src/tally.rs
  • crates/catalog/src/tests.rs
  • crates/catalog/src/tests_album_folder_photos.rs
  • crates/catalog/src/tests_tally.rs
  • crates/engine/src/album_counts.rs
  • crates/engine/src/cmd/library/filters.rs
  • crates/engine/src/cmd/library/specs.rs
  • crates/engine/src/cmd/query.rs
  • crates/engine/src/lib.rs
  • crates/engine/src/tests.rs
  • crates/engine/src/tests/album_counts.rs
  • crates/engine/src/tests/album_folder_source.rs
  • crates/engine/src/tests/view_follow.rs
  • crates/ui-egui/src/caches.rs
  • crates/ui-egui/src/control.rs
  • crates/ui-egui/src/headless.rs
  • crates/ui-egui/src/lib.rs
  • crates/ui-egui/src/panels/left/albums.rs
  • crates/ui-egui/src/panels/left/folders.rs
  • crates/ui-egui/src/tests.rs
  • crates/ui-egui/src/tests/album_list.rs
  • crates/ui-egui/src/tests/panels.rs
  • docs/control-protocol.md
  • docs/mcp.md
  • docs/parity-checklist.md
  • docs/whats-new.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Walkthrough

The changes add album folders as photo sources, calculate their membership from contained albums, and prevent folder-related album loops. Album listings now use cached counts with age indicators. Keyword-list edits have a separate catalog revision aspect.

Changes: Album folders and counts

Layer / File(s) Summary
Catalog membership and tally
crates/catalog/src/lib.rs, crates/catalog/src/query.rs, crates/catalog/src/tally.rs, crates/catalog/src/tests.rs, crates/catalog/src/tests_album_folder_photos.rs, crates/catalog/src/tests_tally.rs, crates/engine/src/tests/view_follow.rs, crates/ui-egui/src/caches.rs
Folder membership is gathered from contained albums and deduplicated. Folder and smart-album photo queries use gathering passes. Tallies include folders, and keyword-list edits have a separate revision aspect.
Folder sources and loop checks
crates/engine/src/cmd/library/*, crates/engine/src/lib.rs, crates/engine/src/tests/album_folder_source.rs, crates/engine/src/tests/view_follow.rs, crates/ui-egui/src/panels/left/*, crates/ui-egui/src/tests/panels.rs, docs/whats-new.md
Folders can be selected as album sources. Smart-album creation and album moves check for loops involving folders. Tests cover folder views, nested membership, and UI selection behavior.
Album count caching and listing
crates/engine/src/album_counts.rs, crates/engine/src/cmd/query.rs, crates/engine/src/lib.rs, crates/engine/src/tests/album_counts.rs, crates/ui-egui/src/caches.rs, crates/ui-egui/src/control.rs, crates/ui-egui/src/headless.rs, crates/ui-egui/src/lib.rs, crates/ui-egui/src/panels/left/albums.rs, crates/ui-egui/src/tests/album_list.rs, docs/control-protocol.md, docs/mcp.md, docs/parity-checklist.md, docs/whats-new.md
Album listings use cached counts and report whether smart-album or folder counts are pending. The UI updates tallies after edits and can recount in the background. Headless sessions compute and retain counts.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant EngineControl
  participant AlbumCountCache
  participant AlbumTally
  participant Catalog
  participant EngineSession
  EngineControl->>AlbumCountCache: Request counts and age for the library
  AlbumCountCache->>AlbumTally: Build or update tally
  AlbumTally->>Catalog: Gather album members and counts
  AlbumCountCache-->>EngineControl: Return counts and age
  EngineControl->>EngineSession: Offer counts and run albums.list
  EngineSession-->>EngineControl: Return album list with countPending status
Loading

Possibly related issues

Suggested reviewers: aiongg, echelon

Merge Risk: Minimal · up to e048d

This change makes folders usable as album sources and speeds up albums.list by reusing cached counts. No merge-blocking defect was found in the supplied review evidence. The folder-loop checks, keyword-list revision tracking and recount fallbacks are covered by the added tests.

Security architecture risk: Low · up to e048d

Folder sources and cached counts add state and freshness behavior. The reviewed paths keep libraries separate and preserve deletion and loop protections; no new security defect was established. Background recovery behavior and unreviewed paths leave some uncertainty.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected caller-controlled album identities affect membership, views, and count responses within the active library. Cached counts do not grant access to another catalog or determine mutation authority in the reviewed consumers.

Trust Boundaries and Controls

  • observed — Count jobs and published caches carry library identity. Collection discards another library's job, and current status requires matching library, catalog revision, and clock minute. Library replacement changes the session generation and assigns loaded catalogs distinct revision ranges.

Resilience and Maintainability Implications

  • observed — One retained job prevents duplicate recount scheduling. Panics are caught, disconnected channels become failures, and failures retain prior display values while suppressing identical retries. A connected worker without a result remains pending; the inspected lifecycle has no timeout or cancellation recovery. No concrete security impact from that conditional state was established.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 78.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: using sidebar-maintained counts for folder entries in albums.list. The stacked PR references add context but do not make the title misleading.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 78.46% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 65 functions across 24 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.0)

Clippy execution timed out

Comment @coderabbitai help to get the list of available commands.

@eliets2 eliets2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First-pass review notes (automated; combined from specialist angles: tests). Please treat as suggestions and verify before acting.

Summary: This PR makes albums.list take a folder album's count from the kept counts in AlbumTally instead of counting every photo for each folder with Catalog::album_count, and reports countPending for folders as for smart albums. AlbumTally now counts folders from the albums inside them, OR-ing the smart albums' kept photos, adding the other albums' chosen photos, and excluding deleted photos, with edits to a few photos following the albums inside the folder.

Logical units:

  • AlbumTally folder counting in crates/catalog/src/tally.rs
  • albums.list folder count and countPending from kept counts
  • Documentation updates in docs/control-protocol.md, docs/mcp.md, and docs/whats-new.md
  • Tests in crates/catalog/src/tests_tally.rs, tally.rs, crates/engine/src/tests/view_follow.rs, crates/engine/src/tests/album_counts.rs, and crates/ui-egui/src/tests/album_list.rs

Findings:

  • [tests] crates/catalog/src/tally.rs (AlbumTally::counted/follow), crates/catalog/src/tests_tally.rs: no test compares a folder's kept count against the expected value — the note ends there; add a test in tests_tally.rs that compares a folder's kept count from counted/follow against the expected count.

Overlaps: Stacked on #768 and #3387, whose heads are merged as the base; #3387 is itself stacked on #2020. The PR is described as part of #768 and #3387.

Verdict: needs changes — 1) the [tests] finding above is the only finding reported; no other findings were reported in the specialist notes provided.

@nledford

nledford commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@eliets2 thanks for the first-pass notes. I checked the one point against the current head and changed nothing in this PR:

  • No test compares a folder's kept count with the expected value: three tests do, each against an independent count of the same catalog:
    • a_whole_count_equals_each_album_counted_alone (tests_tally.rs) builds folders (nested, and an empty one) with chosen-photo and smart albums inside, and checks that AlbumTally::of gives every folder the count Catalog::album_count gives it alone, before and after an edit.
    • the_albums_counts_followed_through_edits_are_the_counts_made_from_every_photo (view_follow.rs) keeps nested folders through a long random run of edits and checks that the followed counts equal the counts made from every photo after each look.
    • a_folder_is_counted_with_the_albums_inside_it_and_is_pending_with_them (album_counts.rs) pins the numbers albums.list reports for folders ((2, false), (4, false)) and the countPending of a folder holding a smart album with a clock rule.
  • Stacked on LR-LIB-FOLDER: a folder of albums shows the photos of the albums inside it #768 and LR-LIB-SMARTALBUM: albums.list answers at once from the counts the sidebar keeps (stacked on #2020) #3387: yes, as the first line of the body says; they merge first.

@vangel76 vangel76 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed e048d414. I checked the stacked folder count changes and the public count regressions. I found one repeated traversal after a photo-only edit. The submitted branch currently conflicts with main.

Source review only. I did not build the project, run tests, or check CI.

}
// After the albums inside them, whose photos they are put together from. No deleted photo is in a folder's count.
for folder in &folders {
let inside = cat.album_members(*folder);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. Preserve flattened folder membership across photo-only tally updates. A small edit such as rating one photo runs album_members for every folder during sidebar counting. That scans albums and their parent chains before checking the changed photo. In a large nested library the work repeats on the UI thread. Store the membership with the tally and invalidate it on album structure changes. Verify reused membership during a photo edit and refreshed counts after reparenting.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants