fix(home): server-owned growth window; expose days

Home omits growth_days; backend auto (or home_growth_days 1/7) picks
the window. Response includes days alongside growth_days. Growth榜 link
uses the returned days. Non-growth sorts treat omitted/auto as 7.
This commit is contained in:
bot-ci committed 2026-11-02 10:05:00 +08:00
1 parent 9163f47b76
commit 297d9279d8
5 files changed
+52 -28

No files matched your search

+25 -18
View File
@@ -699,7 +699,7 @@ class DashboardQueries:
sort: str = "heat",
within_days: int | None = None,
year: int | None = None,
growth_days: int | str = 7,
growth_days: int | str = "auto",
folder_id: int | None = None,
q: str | None = None,
page: int = 1,
@@ -734,7 +734,7 @@ class DashboardQueries:
sort: str = "heat",
within_days: int | None = None,
year: int | None = None,
growth_days: int | str = 7,
growth_days: int | str = "auto",
folder_id: int | None = None,
q: str | None = None,
page: int = 1,
@@ -742,24 +742,29 @@ class DashboardQueries:
) -> dict[str, Any]:
if sort not in VIDEO_SORTS:
raise ValueError(f"不支持的排序: {sort}")
# auto:仅增长类排序由服务端选窗(配置 home_growth_days;默认先 7 再降 1)。
# 首页应省略 growth_days,勿自行探查。其它排序把 auto 当作 7(兼容旧默认)。
if growth_days == "auto":
preferred = self.config_store.get().analytics.home_growth_days
if preferred in (1, 7):
growth_days = int(preferred)
if sort in {"growth", "growth_rate"}:
preferred = self.config_store.get().analytics.home_growth_days
if preferred in (1, 7):
growth_days = int(preferred)
else:
trial = self._list_videos_uncached(
sort=sort,
within_days=within_days,
year=year,
growth_days=7,
folder_id=folder_id,
q=q,
page=page,
page_size=page_size,
)
if trial.get("available") and int(trial.get("total") or 0) > 0:
return trial
growth_days = 1
else:
trial = self._list_videos_uncached(
sort=sort,
within_days=within_days,
year=year,
growth_days=7,
folder_id=folder_id,
q=q,
page=page,
page_size=page_size,
)
if trial.get("available") and int(trial.get("total") or 0) > 0:
return trial
growth_days = 1
growth_days = 7
growth_days = int(growth_days)
if growth_days < 1 or growth_days > 365:
raise ValueError("growth_days 必须在 1~365 之间")
@@ -942,6 +947,8 @@ class DashboardQueries:
"within_days": within_days,
"year": year,
"growth_days": growth_days,
# days:与 growth_days 同步;首页 auto 时为 1|7,供前端链接/展示
"days": growth_days,
"page": page,
"page_size": page_size,
"total": total,