mirror of
https://example.com
synced 2024-11-22 11:16:38 +09:00
refactor: remove more unnecessary chart code (close #74)
This commit is contained in:
parent
297443cf8c
commit
0c32eb6907
7 changed files with 4 additions and 98 deletions
|
@ -528,15 +528,6 @@ export default function () {
|
|||
processObjectStorage(objectStorageQueue);
|
||||
processBackground(backgroundQueue);
|
||||
|
||||
systemQueue.add(
|
||||
"tickCharts",
|
||||
{},
|
||||
{
|
||||
repeat: { cron: "55 * * * *" },
|
||||
removeOnComplete: true,
|
||||
},
|
||||
);
|
||||
|
||||
systemQueue.add(
|
||||
"cleanCharts",
|
||||
{},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Record<string, unknown>>,
|
||||
done: any,
|
||||
): Promise<void> {
|
||||
logger.info("Tick charts...");
|
||||
await activeUsersChart.tick(false);
|
||||
logger.succ("All charts successfully ticked.");
|
||||
done();
|
||||
}
|
|
@ -17,14 +17,6 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
|||
super(name, schema);
|
||||
}
|
||||
|
||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
public read(user: {
|
||||
id: User["id"];
|
||||
host: null;
|
||||
|
|
|
@ -163,16 +163,6 @@ export default abstract class Chart<T extends Schema> {
|
|||
date: number;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* 1日に一回程度実行されれば良いような計算処理を入れる(主にCASCADE削除などアプリケーション側で感知できない変動によるズレの修正用)
|
||||
*/
|
||||
protected abstract tickMajor(group: string | null): Promise<Partial<KVs<T>>>;
|
||||
|
||||
/**
|
||||
* 少なくとも最小スパン内に1回は実行されて欲しい計算処理を入れる
|
||||
*/
|
||||
protected abstract tickMinor(group: string | null): Promise<Partial<KVs<T>>>;
|
||||
|
||||
private static convertSchemaToColumnDefinitions(
|
||||
schema: Schema,
|
||||
): Record<string, { type: string; array?: boolean; default?: any }> {
|
||||
|
@ -680,58 +670,6 @@ export default abstract class Chart<T extends Schema> {
|
|||
);
|
||||
}
|
||||
|
||||
public async tick(
|
||||
major: boolean,
|
||||
group: string | null = null,
|
||||
): Promise<void> {
|
||||
const data = major
|
||||
? await this.tickMajor(group)
|
||||
: await this.tickMinor(group);
|
||||
|
||||
const columns = {} as Record<keyof Columns<T>, 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<T>;
|
||||
columns[name] = v;
|
||||
}
|
||||
|
||||
if (Object.keys(columns).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const update = async (
|
||||
logHour: RawRecord<T>,
|
||||
logDay: RawRecord<T>,
|
||||
): Promise<void> => {
|
||||
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<void> {
|
||||
return this.tick(true, group);
|
||||
}
|
||||
|
||||
public async clean(): Promise<void> {
|
||||
const current = dateUTC(Chart.getCurrentDate());
|
||||
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue