Prefer Scryfall's representative printing for default card images
Card previews were picking whichever printing happened to load first during ingest (ORDER BY rowid over every printing, promos and foreign versions included), so a card's default image was effectively random. Capture the representative printing's images straight from the Oracle Cards bulk pass instead, and prefer that over the old printings-table guess, falling back gracefully on an older reference.db that predates these columns. Also add docs/printing-tracking-design.md, a design (not yet implemented) for optionally tracking which specific printing/finish a library or deck card is.
This commit is contained in:
@@ -85,8 +85,8 @@ impl Catalog {
|
||||
JOIN {REF_DB}.oracle_cards oc ON oc.oracle_id = lc.oracle_id
|
||||
WHERE lc.quantity_owned > 0
|
||||
ORDER BY oc.name COLLATE NOCASE",
|
||||
image = crate::db::image_subquery("image_uri"),
|
||||
back = crate::db::image_subquery("back_image_uri"),
|
||||
image = self.image_expr("image_uri"),
|
||||
back = self.image_expr("back_image_uri"),
|
||||
price = crate::db::price_subquery(),
|
||||
horizontal = self.horizontal_col()
|
||||
))?;
|
||||
@@ -314,6 +314,36 @@ mod tests {
|
||||
assert_eq!(stats.color_counts, [0, 0, 1, 0, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oracle_cards_image_wins_over_the_printings_pick() {
|
||||
// The bug this guards: `printings` can hold an arbitrary (promo,
|
||||
// showcase, foreign-language...) printing per card. `oracle_cards`'s
|
||||
// own image — Scryfall's representative-printing pick, captured at
|
||||
// ingest — must win when present, rather than whatever `printings`
|
||||
// subquery would otherwise resolve to (first by rowid).
|
||||
let fx = test_support::make();
|
||||
let cat = &fx.catalog;
|
||||
cat.connection()
|
||||
.execute(
|
||||
"UPDATE ref.printings SET image_uri = 'http://img/promo-variant' \
|
||||
WHERE oracle_id = 'sol-ring'",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
cat.connection()
|
||||
.execute(
|
||||
"UPDATE ref.oracle_cards SET image_uri = 'http://img/normal' \
|
||||
WHERE oracle_id = 'sol-ring'",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
cat.add_owned("sol-ring", 1).unwrap();
|
||||
|
||||
let lib = cat.list_library().unwrap();
|
||||
let sol = lib.iter().find(|c| c.card.oracle_id == "sol-ring").unwrap();
|
||||
assert_eq!(sol.card.image_uri, "http://img/normal");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn back_image_uri_is_plumbed_through() {
|
||||
let fx = test_support::make();
|
||||
|
||||
Reference in New Issue
Block a user