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);
|
processObjectStorage(objectStorageQueue);
|
||||||
processBackground(backgroundQueue);
|
processBackground(backgroundQueue);
|
||||||
|
|
||||||
systemQueue.add(
|
|
||||||
"tickCharts",
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
repeat: { cron: "55 * * * *" },
|
|
||||||
removeOnComplete: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
systemQueue.add(
|
systemQueue.add(
|
||||||
"cleanCharts",
|
"cleanCharts",
|
||||||
{},
|
{},
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
import { tickCharts } from "./tick-charts.js";
|
|
||||||
import { cleanCharts } from "./clean-charts.js";
|
import { cleanCharts } from "./clean-charts.js";
|
||||||
import { checkExpiredMutings } from "./check-expired-mutings.js";
|
import { checkExpiredMutings } from "./check-expired-mutings.js";
|
||||||
import { clean } from "./clean.js";
|
import { clean } from "./clean.js";
|
||||||
|
@ -7,7 +6,6 @@ import { setLocalEmojiSizes } from "./local-emoji-size.js";
|
||||||
import { verifyLinks } from "./verify-links.js";
|
import { verifyLinks } from "./verify-links.js";
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
tickCharts,
|
|
||||||
cleanCharts,
|
cleanCharts,
|
||||||
checkExpiredMutings,
|
checkExpiredMutings,
|
||||||
clean,
|
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);
|
super(name, schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
public read(user: {
|
public read(user: {
|
||||||
id: User["id"];
|
id: User["id"];
|
||||||
host: null;
|
host: null;
|
||||||
|
|
|
@ -163,16 +163,6 @@ export default abstract class Chart<T extends Schema> {
|
||||||
date: number;
|
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(
|
private static convertSchemaToColumnDefinitions(
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
): Record<string, { type: string; array?: boolean; default?: any }> {
|
): 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> {
|
public async clean(): Promise<void> {
|
||||||
const current = dateUTC(Chart.getCurrentDate());
|
const current = dateUTC(Chart.getCurrentDate());
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,4 @@ export const activeUsersChart = new ActiveUsersChart();
|
||||||
// 20分おきにメモリ情報をDBに書き込み
|
// 20分おきにメモリ情報をDBに書き込み
|
||||||
setInterval(() => activeUsersChart.save(), 1000 * 60 * 20);
|
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 { Not, In } from "typeorm";
|
||||||
import type { User, ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
import type { User, ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
|
import { activeUsersChart } from "@/services/chart/index.js";
|
||||||
import type { IPoll } from "@/models/entities/poll.js";
|
import type { IPoll } from "@/models/entities/poll.js";
|
||||||
import { Poll } from "@/models/entities/poll.js";
|
import { Poll } from "@/models/entities/poll.js";
|
||||||
import { createNotification } from "../create-notification.js";
|
import { createNotification } from "../create-notification.js";
|
||||||
|
@ -434,6 +435,8 @@ export default async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
|
if (Users.isLocalUser(user)) activeUsersChart.write(user);
|
||||||
|
|
||||||
// 未読通知を作成
|
// 未読通知を作成
|
||||||
if (data.visibility === "specified") {
|
if (data.visibility === "specified") {
|
||||||
if (data.visibleUsers == null) throw new Error("invalid param");
|
if (data.visibleUsers == null) throw new Error("invalid param");
|
||||||
|
|
Loading…
Add table
Reference in a new issue