1
0

fix: didn't read correct property when reading from cache

This commit is contained in:
alikia2x (寒寒) 2025-11-28 23:52:37 +08:00
parent 92db443e6b
commit 10d8126de4
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
5 changed files with 24 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import { Elysia, t } from "elysia";
import { db, videoSnapshot } from "@core/drizzle";
import { bv2av } from "@backend/lib/bilibiliID";
import { biliIDToAID, bv2av } from "@backend/lib/bilibiliID";
import { getVideoInfo } from "@core/net/getVideoInfo";
import { redis } from "@core/db/redis";
import { ErrorResponseSchema } from "@backend/src/schema";
@ -46,13 +46,9 @@ export const getVideoMetadataHandler = new Elysia({ prefix: "/video" }).get(
"/:id/info",
async (c) => {
const id = c.params.id;
let aid: number | null = null;
const aid = biliIDToAID(id);
if (id.startsWith("BV1")) {
aid = bv2av(id as `BV1${string}`);
} else if (id.startsWith("av")) {
aid = Number.parseInt(id.slice(2));
} else {
if (!aid) {
return c.status(400, {
code: "MALFORMED_SLOT",
message:
@ -63,7 +59,7 @@ export const getVideoMetadataHandler = new Elysia({ prefix: "/video" }).get(
const cachedData = await retrieveVideoInfoFromCache(aid);
if (cachedData) {
return cachedData;
return cachedData.data;
}
const r = await getVideoInfo(aid, "getVideoInfo");

View File

@ -1,6 +1,6 @@
import { Elysia } from "elysia";
import { db, videoSnapshot } from "@core/drizzle";
import { bv2av } from "@backend/lib/bilibiliID";
import { biliIDToAID, bv2av } from "@backend/lib/bilibiliID";
import { ErrorResponseSchema } from "@backend/src/schema";
import { eq, desc } from "drizzle-orm";
import z from "zod";
@ -10,13 +10,9 @@ export const getVideoSnapshotsHandler = new Elysia({ prefix: "/video" }).get(
"/:id/snapshots",
async (c) => {
const id = c.params.id;
let aid: number | null = null;
const aid = biliIDToAID(id);
if (id.startsWith("BV1")) {
aid = bv2av(id as `BV1${string}`);
} else if (id.startsWith("av")) {
aid = Number.parseInt(id.slice(2));
} else {
if (!aid) {
return c.status(400, {
code: "MALFORMED_SLOT",
message:

View File

@ -1,5 +1,5 @@
import { Job } from "bullmq";
import { insertVideoSnapshot } from "mq/task/getVideoStats";
import { takeVideoSnapshot } from "mq/task/getVideoStats";
import { sql } from "@core/db/dbNew";
import { lockManager } from "@core/mq/lockManager";
@ -12,6 +12,6 @@ export const directSnapshotWorker = async (job: Job): Promise<void> => {
if (!aid) {
throw new Error("aid does not exists");
}
await insertVideoSnapshot(sql, aid, "snapshotMilestoneVideo");
await takeVideoSnapshot(sql, aid, "snapshotMilestoneVideo");
await lockManager.acquireLock(`directSnapshot-${job.data.aid}`, 75);
};

View File

@ -8,7 +8,7 @@ import {
import logger from "@core/log";
import { HOUR, MINUTE, SECOND } from "@core/lib";
import { getBiliVideoStatus, setBiliVideoStatus } from "../../db/bilibili_metadata";
import { insertVideoSnapshot } from "mq/task/getVideoStats";
import { takeVideoSnapshot } from "mq/task/getVideoStats";
import { getSongsPublihsedAt } from "db/songs";
import { getAdjustedShortTermETA } from "mq/scheduling";
import { NetSchedulerError } from "@core/net/delegate";
@ -45,7 +45,7 @@ export const snapshotVideoWorker = async (job: Job): Promise<void> => {
}
await setSnapshotStatus(sql, id, "processing");
const stat = await insertVideoSnapshot(sql, aid, task);
const stat = await takeVideoSnapshot(sql, aid, task);
if (typeof stat === "number") {
await setBiliVideoStatus(aid, stat);
await setSnapshotStatus(sql, id, "bili_error");

View File

@ -1,6 +1,7 @@
import { getVideoInfo } from "@core/net/getVideoInfo";
import logger from "@core/log";
import type { Psql } from "@core/db/psql.d";
import { insertVideoSnapshot } from "db/snapshot";
export interface SnapshotNumber {
time: number;
@ -24,7 +25,7 @@ export interface SnapshotNumber {
* - The native `fetch` function threw an error: with error code `FETCH_ERROR`
* - The alicloud-fc threw an error: with error code `ALICLOUD_FC_ERROR`
*/
export async function insertVideoSnapshot(
export async function takeVideoSnapshot(
sql: Psql,
aid: number,
task: string
@ -42,10 +43,17 @@ export async function insertVideoSnapshot(
const shares = data.stat.share;
const favorites = data.stat.favorite;
await sql`
INSERT INTO video_snapshot (aid, views, danmakus, replies, likes, coins, shares, favorites, created_at)
VALUES (${aid}, ${views}, ${danmakus}, ${replies}, ${likes}, ${coins}, ${shares}, ${favorites}, ${new Date(time).toISOString()})
`;
await insertVideoSnapshot({
createdAt: new Date(time).toISOString(),
views,
coins,
likes,
favorites,
shares,
danmakus,
replies,
aid
})
logger.log(`Taken snapshot for video ${aid}.`, "net", "fn:insertVideoSnapshot");