Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

perf(web): 馆藏网格视口外的卡片跳过渲染

longmeidaof0d9ff199d29
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index b27fce113..3c9139f1e 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -2678,6 +2678,28 @@ class WebUiSourceTests(unittest.TestCase):
# 回收站卡片的缩略图不描边,抵消的对象也得跟着是伪元素。
self.assertPageContains(".junkcard:hover .pic::after{content:none}")
+ def test_catalog_cards_skip_rendering_outside_the_viewport(self):
+ """馆藏网格的卡片交给浏览器按视口取舍,一屏滚动只算屏上那几十张。
+
+ 连续加载到 1525 张时帧间隔 18.2 ms,仍在 16.7 ms 的帧预算附近(ADR-0031
+ 「馆藏网格连续加载的实测」)。`auto 320px` 只是占位,渲染过的卡记住自己的尺寸。
+
+ 四类卡在规则之外。Mix 卡和分卷/版次卡的叠层纸边靠 transform 抬到卡片盒外
+ 7px,跳过渲染连带的 paint containment 会把那一截裁掉;垃圾文件卡自己声明占位
+ 高度,这条选择器压过去会把它改矮;竖屏带的卡横着排在 `.srow` 里,320px 与
+ 9:16 的封面对不上。
+ """
+ cards = (Path(__file__).resolve().parents[1]
+ / "web/css/12-cards.css").read_text(encoding="utf-8")
+ selector = "#grid article.card:not(.mixcard,.partcard,.junkcard,.scard){"
+ self.assertIn(selector, cards, "跳过渲染只施加给馆藏网格里不带叠层的卡片")
+ rule = cards[cards.index(selector) + len(selector):]
+ rule = rule[:rule.index("}")]
+ self.assertIn("content-visibility:auto", rule)
+ self.assertIn("contain-intrinsic-size:auto 320px", rule)
+ # 垃圾文件卡的占位高度归它自己,所以它留在上面那条的 `:not()` 里。
+ self.assertIn("content-visibility:auto;contain-intrinsic-size:auto 360px", cards)
+
def test_big_jav_layout_crops_to_the_front_cover(self):
"""大图=宽度不变、高度拉长,只留封套右侧那块正封。
diff --git a/web/css/12-cards.css b/web/css/12-cards.css
index c90f0cd74..0eff533e6 100644
--- a/web/css/12-cards.css
+++ b/web/css/12-cards.css
@@ -139,6 +139,14 @@ body.refreshing #batchAction svg,
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(var(--tile),1fr));gap:16px 8px}
.card{cursor:pointer;display:flex;flex-direction:column;gap:8px;min-width:0;
position:relative;transition:transform .18s ease,filter .18s ease;transform-origin:center}
+/* 视口外的卡片跳过渲染:一屏滚动要算的只剩屏上那几十张,连续加载到一千五百张时帧间隔
+ 仍在预算附近(实测见 ADR-0031「馆藏网格连续加载的实测」)。`auto 320px` 是占位高度,
+ 没渲染过的卡先按 320px 排进来,渲染过的记住自己的实际尺寸。
+ 四类卡不在其内:Mix 卡和分卷/版次卡的叠层纸边靠 transform 抬到卡片盒外 7px,跳过渲染
+ 连带的 paint containment 会把那一截裁掉;垃圾文件卡自己声明了更高的占位值;竖屏带的卡
+ 横着排在 `.srow` 里,320px 与 9:16 的封面对不上。 */
+#grid article.card:not(.mixcard,.partcard,.junkcard,.scard){
+ content-visibility:auto;contain-intrinsic-size:auto 320px}
/* 叠层往上溢出到行间距里,卡片本体不为它留白。留白的写法(padding-top:7px)会把
整张卡压低 7px 并加高 7px,同一行里 Mix、分卷、版次卡的封面和下面的文字就比
邻居矮一截;往上堆之后卡片盒和普通卡完全同高,下沿自然平齐。 */