From 368c04925500e9ccc1eb446c9e683750c1307a49 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Sun, 11 Jan 2026 22:25:37 +0800 Subject: [PATCH] update: the archive script --- .idea/data_source_mapping.xml | 3 +++ src/fullSnapshot.ts | 28 +++++++++++++++++----------- src/getAllAids.ts | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/getAllAids.ts diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml index e4023f1..90c8c3b 100644 --- a/.idea/data_source_mapping.xml +++ b/.idea/data_source_mapping.xml @@ -9,6 +9,7 @@ + @@ -17,6 +18,8 @@ + + \ No newline at end of file diff --git a/src/fullSnapshot.ts b/src/fullSnapshot.ts index 4af600d..4317680 100644 --- a/src/fullSnapshot.ts +++ b/src/fullSnapshot.ts @@ -1,5 +1,5 @@ import { Database } from "bun:sqlite"; -import { sql } from "@core/index"; +import { sql } from "@core/db/dbNew"; import logger from "@core/log"; import { getVideoDetails } from "@core/net/getVideoDetails"; import arg from "arg"; @@ -45,16 +45,22 @@ async function addCandidates() { const newAids = aids.filter((aid) => !existingAidsSet.has(aid)); - let i = 0; - for (const aid of newAids) { - const stmt = sqlite.query( - `INSERT INTO bili_info_crawl (aid, status) VALUES ($aid, 'pending');` - ); - stmt.all({ $aid: aid }); - i++; - logger.log(`Added ${i} to local DB.`); - } - logger.log(`Added ${newAids.length} to local DB.`); + const insertStmt = sqlite.prepare( + `INSERT INTO bili_info_crawl (aid, status) VALUES (?, 'pending') ON CONFLICT DO NOTHING;` + ); + + const insertMany = sqlite.transaction((data) => { + for (const aid of data) { + insertStmt.run(aid); + } + }); + + try { + insertMany(newAids); + logger.log(`Successfully added ${newAids.length} to local DB.`); + } catch (err) { + logger.error(["Failed to insert candidates:", err]); + } } async function insertAidsToDB() { diff --git a/src/getAllAids.ts b/src/getAllAids.ts new file mode 100644 index 0000000..9b3ea6a --- /dev/null +++ b/src/getAllAids.ts @@ -0,0 +1,2 @@ +import { getLatestVideoAids } from "@crawler/net/getLatestVideoAids"; +