Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos by id find shared albums' photos too, as the grid asks for them

Yashwanth Kamireddi22809d58234c
diff --git a/.uiverify/photos-shared.mjs b/.uiverify/photos-shared.mjs
index d8c8993..b60d9c7 100644
--- a/.uiverify/photos-shared.mjs
+++ b/.uiverify/photos-shared.mjs
@@ -40,6 +40,15 @@ ok((await page.getByRole("button", { name: "New Shared Album" }).count()) === 0,
await page.locator(".px-albums-page .px-card", { hasText: "Wallpapers" }).click();
await page.waitForTimeout(350);
ok((await page.locator(".px-bar h1").innerText()) === "Wallpapers" && (await page.locator(".px-tile").count()) === 2, "a card opens the album: its photos, under its name");
+// Left open, the album asks for nothing more: a shared photo the backend couldn't find by id
+// had the grid ask for it again every frame, and its tiles flickered.
+const gets = () => page.evaluate(() => (window.__gets ?? []).length);
+await page.evaluate(() => window.__emit?.("quince://synced", { services: [{ service: "photos", label: "Photos", outcome: "ok", detail: null, lastSyncedAt: Math.floor(Date.now() / 1000) }], asOf: Math.floor(Date.now() / 1000), tookMs: 10, changed: ["photos"] }));
+await page.waitForTimeout(600);
+const settled = await gets();
+await page.mouse.wheel(0, 200);
+await page.waitForTimeout(1000);
+ok((await gets()) === settled, `an open shared album stops asking for its photos after a sync (${settled} → ${await gets()})`);
const albumAfterSync = async () => { await page.evaluate(() => window.__emit?.("quince://synced", { services: [{ service: "photos", label: "Photos", outcome: "ok", detail: null, lastSyncedAt: Math.floor(Date.now() / 1000) }], asOf: Math.floor(Date.now() / 1000), tookMs: 10, changed: ["photos"] })); await page.waitForTimeout(300); };
await albumAfterSync();
ok((await page.locator(".px-bar h1").innerText()) === "Wallpapers", "and stays open when a sync lands (it is in no album list of yours)");
diff --git a/crates/quince-core/src/photos.rs b/crates/quince-core/src/photos.rs
index a647efb..b30a0a1 100644
--- a/crates/quince-core/src/photos.rs
+++ b/crates/quince-core/src/photos.rs
@@ -1229,12 +1229,22 @@ impl Library {
let mut stmt = self
.conn
.prepare_cached(&format!("SELECT {COLUMNS} FROM photos WHERE id = ?1"))?;
+ let mut elsewhere = Vec::new();
for id in ids {
- if let Some(p) = stmt.query_row(params![id], row_to_photo).optional()? {
+ match stmt.query_row(params![id], row_to_photo).optional()? {
+ Some(p) => out.push(p),
+ None => elsewhere.push(id),
+ }
+ }
+ let mut out = self.with_bursts(out)?;
+ // A shared album's photo, which the library itself doesn't hold: found where it is, or
+ // a grid on a shared album asked for its photos, got none, and asked again every frame.
+ for id in elsewhere {
+ if let Some((p, _)) = self.shared_photo(id)? {
out.push(p);
}
}
- self.with_bursts(out)
+ Ok(out)
}
/// The library's months, newest first, each with how many it holds and the photos that stand
diff --git a/crates/quince-core/src/shared.rs b/crates/quince-core/src/shared.rs
index b6db5a9..206f0a7 100644
--- a/crates/quince-core/src/shared.rs
+++ b/crates/quince-core/src/shared.rs
@@ -313,6 +313,28 @@ mod tests {
assert_eq!((shapes[0].width, shapes[0].height), (1200, 2600));
}
+ /// The grid asks for photos by id as it scrolls: a shared album's are found too (left
+ /// unfound, the grid asked for them again every frame and its tiles flickered).
+ #[test]
+ fn photos_by_id_finds_shared_ones_too() {
+ let mut lib = Library::in_memory().unwrap();
+ lib.put_photos(&[photo("own", 5)]).unwrap();
+ lib.put_shared_album(
+ &album("SC-a", "A"),
+ &[photo("s1", 10), photo("s2", 9)],
+ None,
+ )
+ .unwrap();
+ let ids: Vec<String> = ["own", "s2", "nope", "s1"].map(String::from).to_vec();
+ let found: Vec<String> = lib
+ .photos_by_ids(&ids)
+ .unwrap()
+ .into_iter()
+ .map(|p| p.id)
+ .collect();
+ assert_eq!(found, ["own", "s2", "s1"]);
+ }
+
/// An album gone on Apple's side (deleted, left, expired) leaves with every photo in it.
#[test]
fn an_album_let_go_of_takes_its_photos() {