From 13ed20cf5c5f119401fcb0c36e20f9af5cd2ff45 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Sat, 5 Apr 2025 06:22:25 +0800 Subject: [PATCH] fix: milestone snapshot being ignore when a pending schedule exists --- packages/crawler/db/snapshot.ts | 6 +----- packages/crawler/main.ts | 2 +- packages/crawler/mq/exec/snapshotTick.ts | 2 +- packages/crawler/mq/task/getVideoDetails.ts | 12 ++++++++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/crawler/db/snapshot.ts b/packages/crawler/db/snapshot.ts index ef8009d..5be2d62 100644 --- a/packages/crawler/db/snapshot.ts +++ b/packages/crawler/db/snapshot.ts @@ -3,13 +3,9 @@ import { LatestSnapshotType } from "db/schema.d.ts"; export async function getVideosNearMilestone(client: Client) { const queryResult = await client.queryObject(` - SELECT ls.* + SELECT ls FROM latest_video_snapshot ls - INNER JOIN - songs s ON ls.aid = s.aid - AND s.deleted = false WHERE - s.deleted = false AND (views >= 90000 AND views < 100000) OR (views >= 900000 AND views < 1000000) OR (views >= 9900000 AND views < 10000000) diff --git a/packages/crawler/main.ts b/packages/crawler/main.ts index 838dc21..3d45345 100644 --- a/packages/crawler/main.ts +++ b/packages/crawler/main.ts @@ -4,4 +4,4 @@ // SO HERE'S A PLACHOLDER EXPORT FOR DENO: export const DENO = "FUCK YOU DENO"; // Oh, maybe export the version is a good idea -export const VERSION = "1.0.17"; +export const VERSION = "1.0.18"; diff --git a/packages/crawler/mq/exec/snapshotTick.ts b/packages/crawler/mq/exec/snapshotTick.ts index 32e7b23..5b89929 100644 --- a/packages/crawler/mq/exec/snapshotTick.ts +++ b/packages/crawler/mq/exec/snapshotTick.ts @@ -161,7 +161,7 @@ export const collectMilestoneSnapshotsWorker = async (_job: Job) => { const minInterval = 1 * SECOND; const delay = truncate(scheduledNextSnapshotDelay, minInterval, maxInterval); const targetTime = now + delay; - await scheduleSnapshot(client, aid, "milestone", targetTime); + await scheduleSnapshot(client, aid, "milestone", targetTime, true); } } catch (e) { logger.error(e as Error, "mq", "fn:collectMilestoneSnapshotsWorker"); diff --git a/packages/crawler/mq/task/getVideoDetails.ts b/packages/crawler/mq/task/getVideoDetails.ts index ee015fd..3d9b90e 100644 --- a/packages/crawler/mq/task/getVideoDetails.ts +++ b/packages/crawler/mq/task/getVideoDetails.ts @@ -42,6 +42,18 @@ export async function insertVideoInfo(client: Client, aid: number) { [data.Card.follower, uid], ); } + + const stat = data.View.stat; + + const query: string = ` + INSERT INTO video_snapshot (aid, views, danmakus, replies, likes, coins, shares, favorites) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8) + `; + await client.queryObject( + query, + [aid, stat.view, stat.danmaku, stat.reply, stat.like, stat.coin, stat.share, stat.favorite], + ); + logger.log(`Inserted video metadata for aid: ${aid}`, "mq"); await ClassifyVideoQueue.add("classifyVideo", { aid }); }