Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9ca0d4d
LR-LIB-FOLDER: a folder of albums holds the photos of the albums insi…
nledford Oct 10, 2026
fb1e00b
LR-LIB-FOLDER: library.source shows a folder of albums
nledford Oct 10, 2026
e1f64d6
LR-LIB-FOLDER: clicking a folder of albums shows its photos
nledford Oct 10, 2026
a45d188
LR-LIB-FOLDER: docs for folders of albums as a source
nledford Oct 10, 2026
bcf18f5
LR-LIB-FOLDER: review fixes in the catalog: one gathering per pass, o…
nledford Oct 10, 2026
bc89f59
LR-LIB-FOLDER: moving an album into folders that contain each other ends
nledford Oct 10, 2026
52fd3f9
LR-LIB-FOLDER: a smart album can't be made in or moved into the folde…
nledford Oct 10, 2026
ea72299
LR-LIB-FOLDER: the Move to menu says why a move was refused; the side…
nledford Oct 10, 2026
e3ee999
LR-LIB-FOLDER: docs for smart albums and the folder they show
nledford Oct 10, 2026
0f7c678
LR-LIB-FOLDER: second review fixes in the catalog
nledford Oct 10, 2026
eb8a53d
LR-LIB-FOLDER: editing a saved view's rules keeps the album or folder…
nledford Oct 10, 2026
0670a24
LR-LIB-FOLDER: a folder is no drop target or Move to choice for a sma…
nledford Oct 10, 2026
0cbb24d
LR-LIB-FOLDER: docs for the second review's fixes
nledford Oct 10, 2026
02cb82e
LR-LIB-FOLDER: a folder view follows edits, and the one-pass test cou…
nledford Oct 19, 2026
0035a8d
LR-LIB-FOLDER: the whole count follows loops through a folder and lea…
nledford Oct 24, 2026
c12dec1
LR-LIB-FOLDER: a folder shown as the source follows the clock of the …
nledford Oct 24, 2026
b7f77a3
LR-LIB-FOLDER: the catalog keeps smart albums off loops, and a loop h…
nledford Oct 10, 2026
189eafa
LR-LIB-FOLDER: every session edit keeps the catalog's loop rule
nledford Oct 10, 2026
5857328
LR-LIB-FOLDER: docs for the loop rule living in the catalog
nledford Oct 10, 2026
6d009ea
LR-LIB-FOLDER: the loop rule looks ahead instead of applying and taki…
nledford Oct 10, 2026
7efa7c3
LR-LIB-FOLDER: note the 32-deep limit of smart albums testing smart a…
nledford Oct 10, 2026
ddf5071
LR-LIB-FOLDER: which albums are on a loop is worked out once per chan…
nledford Oct 10, 2026
419aeb8
LR-LIB-FOLDER: the albums on a loop are found in one walk, not a sear…
nledford Oct 10, 2026
afa4a73
LR-LIB-FOLDER: a loop search reads the album tree once, not once per …
nledford Oct 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 465 additions & 22 deletions crates/catalog/src/lib.rs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions crates/catalog/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,21 @@ pub struct Album {
}

impl Album {
/// The album without its photos: what it is, where it is and what it tests.
pub(crate) fn outline(&self) -> Album {
Album {
id: self.id,
name: self.name.clone(),
parent: self.parent,
folder: self.folder,
photos: Vec::new(),
cover: None,
smart: self.smart.clone(),
quick: self.quick,
order: self.order,
}
}

/// A regular (manual) album.
pub fn new(id: AlbumId, name: impl Into<String>) -> Album {
Album { id, name: name.into(), parent: None, folder: false, photos: Vec::new(), cover: None, smart: None, quick: false, order: None }
Expand Down
37 changes: 22 additions & 15 deletions crates/catalog/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,13 @@ impl Catalog {
let prepared = filter.prepare();
// `within` only decides for the few kept photos: worked out per photo, not hashed
let within_prepared = within.prepare_one();
let mut v: Vec<&Photo> = self
.photos()
.map(|p| p.as_ref())
.filter(|p| filter.matches_in(p, self, &prepared) || (keep.contains(&p.id) && within.matches_in(p, self, &within_prepared)))
.collect();
// one pass: a folder of albums it asks about is gathered once
let mut v: Vec<&Photo> = crate::gathering(|| {
self.photos()
.map(|p| p.as_ref())
.filter(|p| filter.matches_in(p, self, &prepared) || (keep.contains(&p.id) && within.matches_in(p, self, &within_prepared)))
.collect()
});
v.sort_by(|a, b| sort.order(a, b));
v.into_iter().map(|p| p.id).collect()
}
Expand All @@ -503,22 +505,26 @@ impl Catalog {
let listed: std::collections::HashSet<PhotoId> = was.iter().copied().filter(|id| touched.binary_search(id).is_ok()).collect();
let mut ids: Vec<PhotoId> = was.iter().copied().filter(|id| !listed.contains(id)).collect();
let (prepared, within_prepared) = (filter.prepare_one(), within.map(Filter::prepare_one));
for id in touched {
let Some(p) = self.photo(*id) else { continue };
let kept = within.zip(within_prepared.as_ref()).is_some_and(|(w, wp)| listed.contains(id) && w.matches_in(p, self, wp));
if filter.matches_in(p, self, &prepared) || kept {
// (the list is in order without the touched photos, and stays so as each is put back)
let at = ids.partition_point(|other| self.photo(*other).is_some_and(|o| sort.order(o, p).is_lt()));
ids.insert(at, *id);
// one pass: a folder of albums it asks about is gathered once
crate::gathering(|| {
for id in touched {
let Some(p) = self.photo(*id) else { continue };
let kept = within.zip(within_prepared.as_ref()).is_some_and(|(w, wp)| listed.contains(id) && w.matches_in(p, self, wp));
if filter.matches_in(p, self, &prepared) || kept {
// (the list is in order without the touched photos, and stays so as each is put back)
let at = ids.partition_point(|other| self.photo(*other).is_some_and(|o| sort.order(o, p).is_lt()));
ids.insert(at, *id);
}
}
}
});
ids
}

/// How many photos match `filter`: [`Catalog::query`]'s length without its sorting.
pub fn count(&self, filter: &Filter) -> usize {
let prepared = filter.prepare();
self.photos().filter(|p| filter.matches_in(p, self, &prepared)).count()
// one pass: a folder of albums it asks about is gathered once
crate::gathering(|| self.photos().filter(|p| filter.matches_in(p, self, &prepared)).count())
}

/// Year → month → day counts for the "By Date" section (newest first).
Expand Down Expand Up @@ -575,7 +581,8 @@ impl Catalog {
let filter = Filter { person: None, ..filter.clone() };
let mut m: std::collections::HashMap<String, (Person, f64)> = Default::default();
let prepared = filter.prepare();
for p in self.photos().filter(|p| filter.matches_in(p, self, &prepared)) {
let matching: Vec<_> = crate::gathering(|| self.photos().filter(|p| filter.matches_in(p, self, &prepared)).collect());
for p in matching {
let mut seen: Vec<String> = Vec::new();
for r in p.meta.regions.iter().filter(|r| r.kind == lightcraft_meta::RegionKind::Face) {
let Some(name) = r.name.as_deref().map(str::trim).filter(|n| !n.is_empty()) else { continue };
Expand Down
21 changes: 14 additions & 7 deletions crates/catalog/src/tally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::{HashMap, HashSet};

use crate::query::Filter;
use crate::rules::{AlbumPass, MAX_ALBUM_DEPTH};
use crate::{Album, AlbumId, Aspects, Catalog, PhotoId};
use crate::{AlbumId, Aspects, Catalog, PhotoId};

/// The most photos an edit may touch for the counts to follow it photo by photo.
const MAX_FOLLOWED: usize = 256;
Expand Down Expand Up @@ -104,7 +104,8 @@ impl Members {
}
}

/// [`Catalog::album_count`] of every album, as of one revision of the catalog.
/// [`Catalog::album_count`] of every album, as of one revision of the catalog. Folders of albums are not counted:
/// the sidebar shows them no count, and theirs would cost a pass each.
#[derive(Clone, Debug)]
pub struct AlbumTally {
revision: u64,
Expand All @@ -122,9 +123,14 @@ impl AlbumTally {
/// An album whose rules lead into a loop, or through a chain too deep to be sure of, is counted by its rules
/// as before: the pass ends before the first of them (they sort last), so nothing they evaluate reads it.
pub fn of(cat: &Catalog) -> AlbumTally {
// one pass: a folder of albums a smart album is limited to is gathered once
crate::gathering(|| AlbumTally::counted(cat))
}

fn counted(cat: &Catalog) -> AlbumTally {
let heights = chain_heights(cat);
let height_of = |id: AlbumId| heights.get(&id).copied().flatten().filter(|h| *h <= MAX_ALBUM_DEPTH);
let mut smart: Vec<AlbumId> = cat.albums().filter(|a| a.is_smart()).map(|a| a.id).collect();
let mut smart: Vec<AlbumId> = cat.albums().filter(|a| a.is_smart() && !a.folder).map(|a| a.id).collect();
smart.sort_by_key(|id| height_of(*id).unwrap_or(usize::MAX));
let held_by = |id: AlbumId| {
let mut held = Members::none();
Expand Down Expand Up @@ -152,7 +158,7 @@ impl AlbumTally {
counts.insert(*id, held.len());
members.insert(*id, held);
}
for album in cat.albums().filter(|a| !a.is_smart()) {
for album in cat.albums().filter(|a| !a.is_smart() && !a.folder) {
counts.insert(album.id, cat.album_count(album.id));
}
AlbumTally { revision: cat.revision, counts, members }
Expand Down Expand Up @@ -202,7 +208,7 @@ impl AlbumTally {
self.counts.insert(*album, held.len());
}
if changed.any_of(Aspects::PRESENCE) {
for album in cat.albums().filter(|a| !a.is_smart()) {
for album in cat.albums().filter(|a| !a.is_smart() && !a.folder) {
self.counts.insert(album.id, cat.album_count(album.id));
}
}
Expand All @@ -222,12 +228,13 @@ fn chain_heights(cat: &Catalog) -> HashMap<AlbumId, Option<usize>> {
}
let tests = |id: AlbumId| -> Vec<AlbumId> {
let tested = cat.album(id).and_then(|a| a.smart.as_deref()).map(Filter::albums_tested).unwrap_or_default();
tested.into_iter().filter(|t| cat.album(*t).is_some_and(Album::is_smart)).collect()
// (a folder of albums leads to the smart albums inside it, which its photos are gathered from)
tested.into_iter().flat_map(|t| cat.album_members(t)).filter(|t| cat.album(*t).is_some_and(|a| a.is_smart() && !a.folder)).collect()
};
let frame = |id: AlbumId| Frame { id, tests: tests(id), next: 0, tallest: 0, loops: false };
let mut done: HashMap<AlbumId, Option<usize>> = HashMap::new();
let mut open: HashSet<AlbumId> = HashSet::new();
for root in cat.albums().filter(|a| a.is_smart()).map(|a| a.id) {
for root in cat.albums().filter(|a| a.is_smart() && !a.folder).map(|a| a.id) {
if done.contains_key(&root) {
continue;
}
Expand Down
Loading
Loading