feat: home growth auto(7→1) and hourly recent-video snapshot
- Add analytics.home_growth_days (auto|1|7); API growth_days=auto tries 7 then 1 - Homepage shows active window and growth-board link; clearer empty reason - New snapshot_recent scheduler task (schedule.recent_snapshot_minutes/days) - run_recent_videos refreshes new aids only; never touches completed/backup - Full 00:01 job keeps ok=1 skip (covers hourly refresh within 1h); mutex with recent
This commit is contained in:
1 parent
04716aec1b
commit
9163f47b76
15 files changed
+496
-22
No files matched your search
@@ -699,7 +699,7 @@ class DashboardQueries:
|
||||
sort: str = "heat",
|
||||
within_days: int | None = None,
|
||||
year: int | None = None,
|
||||
growth_days: int = 7,
|
||||
growth_days: int | str = 7,
|
||||
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 = 7,
|
||||
growth_days: int | str = 7,
|
||||
folder_id: int | None = None,
|
||||
q: str | None = None,
|
||||
page: int = 1,
|
||||
@@ -742,6 +742,25 @@ class DashboardQueries:
|
||||
) -> dict[str, Any]:
|
||||
if sort not in VIDEO_SORTS:
|
||||
raise ValueError(f"不支持的排序: {sort}")
|
||||
if growth_days == "auto":
|
||||
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
|
||||
growth_days = int(growth_days)
|
||||
if growth_days < 1 or growth_days > 365:
|
||||
raise ValueError("growth_days 必须在 1~365 之间")
|
||||
page = max(1, int(page))
|
||||
@@ -900,7 +919,9 @@ class DashboardQueries:
|
||||
reason = None
|
||||
if sort in {"growth", "growth_rate"} and not growth_available:
|
||||
available = False
|
||||
reason = "需要至少两天的快照才能计算增长"
|
||||
reason = (
|
||||
f"近 {growth_days} 日增长需要至少 {growth_days + 1} 天快照"
|
||||
)
|
||||
duration_filter = None
|
||||
if sort in duration_sorts:
|
||||
duration_filter = {
|
||||
@@ -1571,6 +1592,7 @@ class DashboardQueries:
|
||||
"min_view_for_ranking": cfg.analytics.min_view_for_ranking,
|
||||
"video_shrink_minutes": cfg.analytics.video_shrink_minutes,
|
||||
"shrink_minutes": cfg.analytics.shrink_minutes,
|
||||
"home_growth_days": cfg.analytics.home_growth_days,
|
||||
},
|
||||
"heat_weights": {
|
||||
metric: float(value)
|
||||
@@ -1747,23 +1769,30 @@ class DashboardQueries:
|
||||
running = self._task_running(conn)
|
||||
now = self._now()
|
||||
discover_interval = int(cfg.schedule.discover_minutes) * 60
|
||||
recent_interval = int(cfg.schedule.recent_snapshot_minutes) * 60
|
||||
next_runs = {
|
||||
"fans": int(next_daily_run(now, cfg.schedule.snapshot_at)),
|
||||
"snapshot": int(next_daily_run(now, cfg.schedule.snapshot_at)),
|
||||
"discover": int(now + discover_interval),
|
||||
"snapshot_recent": int(now + recent_interval),
|
||||
}
|
||||
for name, key in (
|
||||
("fans", "fans"),
|
||||
("snapshot", "snapshot"),
|
||||
("discover", "discovery"),
|
||||
("snapshot_recent", "snapshot_recent"),
|
||||
):
|
||||
record = tasks.get(key)
|
||||
if not (isinstance(record, dict) and record.get("finished_at")):
|
||||
continue
|
||||
finished_at = int(record["finished_at"])
|
||||
if name == "discover":
|
||||
if name in {"discover", "snapshot_recent"}:
|
||||
# 只按上次完成推下一档;进行中由 running 展示,不按墙钟抢跑。
|
||||
next_runs[name] = finished_at + discover_interval
|
||||
interval = (
|
||||
recent_interval if name == "snapshot_recent"
|
||||
else discover_interval
|
||||
)
|
||||
next_runs[name] = finished_at + interval
|
||||
else:
|
||||
next_runs[name] = int(
|
||||
next_daily_run(finished_at, cfg.schedule.snapshot_at)
|
||||
@@ -1805,6 +1834,8 @@ class DashboardQueries:
|
||||
"discover_minutes": cfg.schedule.discover_minutes,
|
||||
"snapshot_at": cfg.schedule.snapshot_at,
|
||||
"candidate_ttl_days": cfg.schedule.candidate_ttl_days,
|
||||
"recent_snapshot_minutes": cfg.schedule.recent_snapshot_minutes,
|
||||
"recent_video_days": cfg.schedule.recent_video_days,
|
||||
},
|
||||
"telegram_enabled": bool(cfg.telegram.enabled),
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
sort=_param(query, "sort", "heat"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
growth_days=_int_param(query, "growth_days", 7, 1, 365),
|
||||
growth_days=_growth_days_param(query),
|
||||
folder_id=_optional_int(query, "folder"),
|
||||
q=_optional_str(query, "q"),
|
||||
page=_int_param(query, "page", 1, 1, 1_000_000),
|
||||
@@ -422,7 +422,7 @@ border-color:#3a2c22;color:#f3e9dc}button{background:#e9b97c;color:#2a1a10}}
|
||||
sort=_param(query, "sort", "heat"),
|
||||
within_days=_optional_int(query, "within_days"),
|
||||
year=_year_param(query),
|
||||
growth_days=_int_param(query, "growth_days", 7, 1, 365),
|
||||
growth_days=_growth_days_param(query),
|
||||
folder_id=_optional_int(query, "folder"),
|
||||
q=_optional_str(query, "q"),
|
||||
page=_int_param(query, "page", 1, 1, 1_000_000),
|
||||
@@ -649,6 +649,28 @@ def _year_param(query: Mapping[str, list[str]]) -> int | None:
|
||||
return value
|
||||
|
||||
|
||||
def _growth_days_param(query: Mapping[str, list[str]]) -> int | str:
|
||||
"""榜单传 1~365;首页可传 auto(由查询层按 home_growth_days 解析)。"""
|
||||
raw = _optional_str(query, "growth_days")
|
||||
if raw is None:
|
||||
return 7
|
||||
if raw == "auto":
|
||||
return "auto"
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError as exc:
|
||||
raise ApiError(
|
||||
HTTPStatus.BAD_REQUEST, "bad_request",
|
||||
"growth_days 必须是整数或 auto",
|
||||
) from exc
|
||||
if value < 1 or value > 365:
|
||||
raise ApiError(
|
||||
HTTPStatus.BAD_REQUEST, "bad_request",
|
||||
"growth_days 必须在 1~365 之间",
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
def _int_param(
|
||||
query: Mapping[str, list[str]],
|
||||
name: str,
|
||||
|
||||
@@ -510,6 +510,7 @@ a.live-chip:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--bo
|
||||
.status-grid strong { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 600; }
|
||||
/* 预计下次运行等 3 项:PC 与移动端都保持一行 */
|
||||
.status-grid.status-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.status-grid.status-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
|
||||
.segmented {
|
||||
display: inline-flex;
|
||||
@@ -993,4 +994,4 @@ a.live-chip:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--bo
|
||||
.about-page .panel h2 { font-size: 15px; margin-bottom: 8px; }
|
||||
.about-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13px; line-height: 1.55; }
|
||||
.about-list code { padding: 1px 4px; border-radius: 4px; background: var(--accent-soft); font-size: 12px; }
|
||||
.about-list.about-weights { list-style: none; padding-left: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.about-list.about-weights { list-style: none; padding-left: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
@@ -47,7 +47,8 @@ export async function renderHome(root) {
|
||||
api("/api/overview"),
|
||||
api("/api/videos", { sort: "published", within_days: 14, limit: 6 }),
|
||||
api("/api/videos", { sort: "heat", limit: 6 }),
|
||||
api("/api/videos", { sort: "growth", growth_days: 7, limit: 6 }),
|
||||
// auto:服务端按 analytics.home_growth_days 解析;默认先试 7 天再降到 1 天
|
||||
api("/api/videos", { sort: "growth", growth_days: "auto", limit: 6 }),
|
||||
]);
|
||||
|
||||
const fans = overview.fans;
|
||||
@@ -59,6 +60,13 @@ export async function renderHome(root) {
|
||||
const pending = overview.counts?.candidates_pending || 0;
|
||||
// 候选提示仅对已登录(或未启用鉴权)用户可见,访客不展示运行期信息。
|
||||
const showCandidates = pending > 0 && canAccessProtected();
|
||||
const growthDays = Number(growth.growth_days) || 1;
|
||||
const growthLabel = `近 ${growthDays} 日`;
|
||||
const growthEmptyTitle = growth.reason
|
||||
|| `近 ${growthDays} 日增长暂不可用`;
|
||||
const growthEmptyHint = growthDays <= 1
|
||||
? "当前快照不足,完成至少 2 天快照后即可显示播放增量。"
|
||||
: `需要至少 ${growthDays + 1} 天快照才能计算近 ${growthDays} 日增长。`;
|
||||
|
||||
root.innerHTML = `<section class="page home-page">
|
||||
<header class="page-head home-head">
|
||||
@@ -101,12 +109,12 @@ export async function renderHome(root) {
|
||||
|
||||
<section class="panel">
|
||||
<div class="section-head">
|
||||
<h2>增长动态</h2>
|
||||
<a class="text-link" href="/videos?sort=growth&growth_days=7">增长榜</a>
|
||||
<h2>增长动态 · ${escapeHtml(growthLabel)}</h2>
|
||||
<a class="text-link" href="/videos?sort=growth&growth_days=${growthDays}">增长榜</a>
|
||||
</div>
|
||||
${growth.available && growth.items.length
|
||||
? `<div class="media-grid">${growth.items.map((item, index) => growthCard(item, index)).join("")}</div>`
|
||||
: emptyState("需要至少 2 天快照", growth.reason || "当前只有 1 个数据点,明天开始显示播放增量。")}
|
||||
: emptyState(growthEmptyTitle, growthEmptyHint)}
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
|
||||
@@ -38,6 +38,7 @@ export async function renderSystem(root) {
|
||||
const health = system.snapshot_health || { total: 0, ok: 0, failed: 0 };
|
||||
const counts = system.counts || {};
|
||||
const next = system.next_runs || {};
|
||||
const running = system.running || {};
|
||||
|
||||
const visitExtra = visitStats
|
||||
? `<span class="section-note">近 ${visitStats.days} 天 · ${visitStats.pending ? "含未落库缓冲" : "已落库"}</span>`
|
||||
@@ -92,12 +93,13 @@ export async function renderSystem(root) {
|
||||
|
||||
<section class="panel">
|
||||
${sectionHeader("预计下次运行")}
|
||||
<div class="status-grid status-row-3">
|
||||
<div class="status-grid status-row-4">
|
||||
<div><span>咻咻满粉丝数更新</span><strong>${running.fans ? "运行中" : escapeHtml(formatDateTime(next.fans))}</strong></div>
|
||||
<div><span>视频数据快照 + UP 信息</span><strong>${running.snapshot ? "运行中" : escapeHtml(formatDateTime(next.snapshot))}</strong></div>
|
||||
<div><span>新视频小时同步</span><strong>${running.snapshot_recent ? "运行中" : escapeHtml(formatDateTime(next.snapshot_recent))}</strong></div>
|
||||
<div><span>新视频搜索</span><strong>${running.discover || running.discovery ? "运行中" : escapeHtml(formatDateTime(next.discover))}</strong></div>
|
||||
</div>
|
||||
<p class="section-note">进行中显示「运行中」;空闲时按该任务上次完成时间推算下次运行,不按墙钟抢跑。</p>
|
||||
<p class="section-note">进行中显示「运行中」;空闲时按该任务上次完成时间推算下次运行,不按墙钟抢跑。新视频小时同步与全站快照互斥。</p>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
|
||||
Reference in new issue
Block a user