ref: rename table all_data, bili_user to bilibili_metadata, bilibili_user

This commit is contained in:
alikia2x (寒寒) 2025-03-15 21:27:19 +08:00
parent 93bdddc21e
commit 7104a95af9
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
3 changed files with 13 additions and 13 deletions

View File

@ -3,19 +3,19 @@ import { AllDataType, BiliUserType } from "lib/db/schema.d.ts";
import { modelVersion } from "lib/ml/filter_inference.ts"; import { modelVersion } from "lib/ml/filter_inference.ts";
export async function videoExistsInAllData(client: Client, aid: number) { export async function videoExistsInAllData(client: Client, aid: number) {
return await client.queryObject<{ exists: boolean }>(`SELECT EXISTS(SELECT 1 FROM all_data WHERE aid = $1)`, [aid]) return await client.queryObject<{ exists: boolean }>(`SELECT EXISTS(SELECT 1 FROM bilibili_metadata WHERE aid = $1)`, [aid])
.then((result) => result.rows[0].exists); .then((result) => result.rows[0].exists);
} }
export async function userExistsInBiliUsers(client: Client, uid: number) { export async function userExistsInBiliUsers(client: Client, uid: number) {
return await client.queryObject<{ exists: boolean }>(`SELECT EXISTS(SELECT 1 FROM bili_user WHERE uid = $1)`, [ return await client.queryObject<{ exists: boolean }>(`SELECT EXISTS(SELECT 1 FROM bilibili_user WHERE uid = $1)`, [
uid, uid,
]); ]);
} }
export async function getUnlabelledVideos(client: Client) { export async function getUnlabelledVideos(client: Client) {
const queryResult = await client.queryObject<{ aid: number }>( const queryResult = await client.queryObject<{ aid: number }>(
`SELECT a.aid FROM all_data a LEFT JOIN labelling_result l ON a.aid = l.aid WHERE l.aid IS NULL`, `SELECT a.aid FROM bilibili_metadata a LEFT JOIN labelling_result l ON a.aid = l.aid WHERE l.aid IS NULL`,
); );
return queryResult.rows.map((row) => row.aid); return queryResult.rows.map((row) => row.aid);
} }
@ -29,14 +29,14 @@ export async function insertVideoLabel(client: Client, aid: number, label: numbe
export async function getVideoInfoFromAllData(client: Client, aid: number) { export async function getVideoInfoFromAllData(client: Client, aid: number) {
const queryResult = await client.queryObject<AllDataType>( const queryResult = await client.queryObject<AllDataType>(
`SELECT * FROM all_data WHERE aid = $1`, `SELECT * FROM bilibili_metadata WHERE aid = $1`,
[aid], [aid],
); );
const row = queryResult.rows[0]; const row = queryResult.rows[0];
let authorInfo = ""; let authorInfo = "";
if (row.uid && await userExistsInBiliUsers(client, row.uid)) { if (row.uid && await userExistsInBiliUsers(client, row.uid)) {
const q = await client.queryObject<BiliUserType>( const q = await client.queryObject<BiliUserType>(
`SELECT * FROM bili_user WHERE uid = $1`, `SELECT * FROM bilibili_user WHERE uid = $1`,
[row.uid], [row.uid],
); );
const userRow = q.rows[0]; const userRow = q.rows[0];
@ -56,8 +56,8 @@ export async function getUnArchivedBiliUsers(client: Client) {
const queryResult = await client.queryObject<{ uid: number }>( const queryResult = await client.queryObject<{ uid: number }>(
` `
SELECT ad.uid SELECT ad.uid
FROM all_data ad FROM bilibili_metadata ad
LEFT JOIN bili_user bu ON ad.uid = bu.uid LEFT JOIN bilibili_user bu ON ad.uid = bu.uid
WHERE bu.uid IS NULL; WHERE bu.uid IS NULL;
`, `,
[], [],

View File

@ -18,9 +18,9 @@ export async function insertIntoSongs(client: Client, aid: number) {
INSERT INTO songs (aid, bvid, published_at, duration) INSERT INTO songs (aid, bvid, published_at, duration)
VALUES ( VALUES (
$1, $1,
(SELECT bvid FROM all_data WHERE aid = $1), (SELECT bvid FROM bilibili_metadata WHERE aid = $1),
(SELECT published_at FROM all_data WHERE aid = $1), (SELECT published_at FROM bilibili_metadata WHERE aid = $1),
(SELECT duration FROM all_data WHERE aid = $1) (SELECT duration FROM bilibili_metadata WHERE aid = $1)
) )
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
`, `,

View File

@ -24,19 +24,19 @@ export async function insertVideoInfo(client: Client, aid: number) {
const published_at = formatTimestampToPsql(data.View.pubdate); const published_at = formatTimestampToPsql(data.View.pubdate);
const duration = data.View.duration; const duration = data.View.duration;
await client.queryObject( await client.queryObject(
`INSERT INTO all_data (aid, bvid, description, uid, tags, title, published_at, duration) `INSERT INTO bilibili_metadata (aid, bvid, description, uid, tags, title, published_at, duration)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
[aid, bvid, desc, uid, tags, title, published_at, duration], [aid, bvid, desc, uid, tags, title, published_at, duration],
); );
const userExists = await userExistsInBiliUsers(client, aid); const userExists = await userExistsInBiliUsers(client, aid);
if (!userExists) { if (!userExists) {
await client.queryObject( await client.queryObject(
`INSERT INTO bili_user (uid, username, "desc", fans) VALUES ($1, $2, $3, $4)`, `INSERT INTO bilibili_user (uid, username, "desc", fans) VALUES ($1, $2, $3, $4)`,
[uid, data.View.owner.name, data.Card.card.sign, data.Card.follower], [uid, data.View.owner.name, data.Card.card.sign, data.Card.follower],
); );
} else { } else {
await client.queryObject( await client.queryObject(
`UPDATE bili_user SET fans = $1 WHERE uid = $2`, `UPDATE bilibili_user SET fans = $1 WHERE uid = $2`,
[data.Card.follower, uid], [data.Card.follower, uid],
); );
} }