diff --git a/packages/backend/src/queue/index.ts b/packages/backend/src/queue/index.ts index 20150e414..f9ca155ff 100644 --- a/packages/backend/src/queue/index.ts +++ b/packages/backend/src/queue/index.ts @@ -528,15 +528,6 @@ export default function () { processObjectStorage(objectStorageQueue); processBackground(backgroundQueue); - systemQueue.add( - "tickCharts", - {}, - { - repeat: { cron: "55 * * * *" }, - removeOnComplete: true, - }, - ); - systemQueue.add( "cleanCharts", {}, diff --git a/packages/backend/src/queue/processors/system/index.ts b/packages/backend/src/queue/processors/system/index.ts index 1db400390..a2a148ab3 100644 --- a/packages/backend/src/queue/processors/system/index.ts +++ b/packages/backend/src/queue/processors/system/index.ts @@ -1,5 +1,4 @@ import type Bull from "bull"; -import { tickCharts } from "./tick-charts.js"; import { cleanCharts } from "./clean-charts.js"; import { checkExpiredMutings } from "./check-expired-mutings.js"; import { clean } from "./clean.js"; @@ -7,7 +6,6 @@ import { setLocalEmojiSizes } from "./local-emoji-size.js"; import { verifyLinks } from "./verify-links.js"; const jobs = { - tickCharts, cleanCharts, checkExpiredMutings, clean, diff --git a/packages/backend/src/queue/processors/system/tick-charts.ts b/packages/backend/src/queue/processors/system/tick-charts.ts deleted file mode 100644 index 265242c47..000000000 --- a/packages/backend/src/queue/processors/system/tick-charts.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type Bull from "bull"; - -import { queueLogger } from "../../logger.js"; -import { activeUsersChart } from "@/services/chart/index.js"; - -const logger = queueLogger.createSubLogger("tick-charts"); - -export async function tickCharts( - job: Bull.Job>, - done: any, -): Promise { - logger.info("Tick charts..."); - await activeUsersChart.tick(false); - logger.succ("All charts successfully ticked."); - done(); -} diff --git a/packages/backend/src/services/chart/charts/active-users.ts b/packages/backend/src/services/chart/charts/active-users.ts index 322bfd25b..a99c07dcb 100644 --- a/packages/backend/src/services/chart/charts/active-users.ts +++ b/packages/backend/src/services/chart/charts/active-users.ts @@ -17,14 +17,6 @@ export default class ActiveUsersChart extends Chart { super(name, schema); } - protected async tickMajor(): Promise>> { - return {}; - } - - protected async tickMinor(): Promise>> { - return {}; - } - public read(user: { id: User["id"]; host: null; diff --git a/packages/backend/src/services/chart/core.ts b/packages/backend/src/services/chart/core.ts index d7a524d48..d6bdca8d0 100644 --- a/packages/backend/src/services/chart/core.ts +++ b/packages/backend/src/services/chart/core.ts @@ -163,16 +163,6 @@ export default abstract class Chart { date: number; }>; - /** - * 1日に一回程度実行されれば良いような計算処理を入れる(主にCASCADE削除などアプリケーション側で感知できない変動によるズレの修正用) - */ - protected abstract tickMajor(group: string | null): Promise>>; - - /** - * 少なくとも最小スパン内に1回は実行されて欲しい計算処理を入れる - */ - protected abstract tickMinor(group: string | null): Promise>>; - private static convertSchemaToColumnDefinitions( schema: Schema, ): Record { @@ -680,58 +670,6 @@ export default abstract class Chart { ); } - public async tick( - major: boolean, - group: string | null = null, - ): Promise { - const data = major - ? await this.tickMajor(group) - : await this.tickMinor(group); - - const columns = {} as Record, number>; - for (const [k, v] of Object.entries(data) as [ - keyof typeof data, - number, - ][]) { - const name = (columnPrefix + - (k as string).replaceAll(".", columnDot)) as keyof Columns; - columns[name] = v; - } - - if (Object.keys(columns).length === 0) { - return; - } - - const update = async ( - logHour: RawRecord, - logDay: RawRecord, - ): Promise => { - await Promise.all([ - this.repositoryForHour - .createQueryBuilder() - .update() - .set(columns) - .where("id = :id", { id: logHour.id }) - .execute(), - this.repositoryForDay - .createQueryBuilder() - .update() - .set(columns) - .where("id = :id", { id: logDay.id }) - .execute(), - ]); - }; - - return Promise.all([ - this.claimCurrentLog(group, "hour"), - this.claimCurrentLog(group, "day"), - ]).then(([logHour, logDay]) => update(logHour, logDay)); - } - - public resync(group: string | null = null): Promise { - return this.tick(true, group); - } - public async clean(): Promise { const current = dateUTC(Chart.getCurrentDate()); diff --git a/packages/backend/src/services/chart/index.ts b/packages/backend/src/services/chart/index.ts index e26dd4943..4b8a9278c 100644 --- a/packages/backend/src/services/chart/index.ts +++ b/packages/backend/src/services/chart/index.ts @@ -6,4 +6,4 @@ export const activeUsersChart = new ActiveUsersChart(); // 20分おきにメモリ情報をDBに書き込み setInterval(() => activeUsersChart.save(), 1000 * 60 * 20); -beforeShutdown(async () => await activeUsersChart.save()); +beforeShutdown(async () => await new Promise(() => activeUsersChart.save())); diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 85c85cbd5..3063894e8 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -39,6 +39,7 @@ import type { App } from "@/models/entities/app.js"; import { Not, In } from "typeorm"; import type { User, ILocalUser, IRemoteUser } from "@/models/entities/user.js"; import { genId } from "@/misc/gen-id.js"; +import { activeUsersChart } from "@/services/chart/index.js"; import type { IPoll } from "@/models/entities/poll.js"; import { Poll } from "@/models/entities/poll.js"; import { createNotification } from "../create-notification.js"; @@ -434,6 +435,8 @@ export default async ( } if (!silent) { + if (Users.isLocalUser(user)) activeUsersChart.write(user); + // 未読通知を作成 if (data.visibility === "specified") { if (data.visibleUsers == null) throw new Error("invalid param");