perf: use charts data for stats endpoint

This commit is contained in:
ThatOneCalculator 2023-06-12 01:16:36 -07:00
parent d4ddf2c867
commit bd9f28246b
No known key found for this signature in database
GPG key ID: 8703CACD01000000

View file

@ -1,6 +1,6 @@
import { Instances, NoteReactions, Notes, Users } from "@/models/index.js"; import { Instances, NoteReactions, Notes, Users } from "@/models/index.js";
import define from "../define.js"; import define from "../define.js";
import {} from "@/services/chart/index.js"; import { driveChart, notesChart, usersChart } from "@/services/chart/index.js";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
export const meta = { export const meta = {
@ -60,19 +60,42 @@ export const paramDef = {
} as const; } as const;
export default define(meta, paramDef, async () => { export default define(meta, paramDef, async () => {
// const [
// notesCount,
// originalNotesCount,
// usersCount,
// originalUsersCount,
// reactionsCount,
// //originalReactionsCount,
// instances,
// ] = await Promise.all([
// Notes.count({ cache: 3600000 }), // 1 hour
// Notes.count({ where: { userHost: IsNull() }, cache: 3600000 }),
// Users.count({ cache: 3600000 }),
// Users.count({ where: { host: IsNull() }, cache: 3600000 }),
// NoteReactions.count({ cache: 3600000 }), // 1 hour
// //NoteReactions.count({ where: { userHost: IsNull() }, cache: 3600000 }),
// Instances.count({ cache: 3600000 }),
// ]);
const notesChartData = await notesChart.getChart("hour", 1, null);
const notesCount =
notesChartData.local.total[0] + notesChartData.remote.total[0];
const originalNotesCount = notesChartData.local.total[0];
const usersChartData = await usersChart.getChart("hour", 1, null);
const usersCount =
usersChartData.local.total[0] + usersChartData.remote.total[0];
const originalUsersCount = usersChartData.local.total[0];
const driveChartData = await driveChart.getChart("hour", 1, null);
const driveUsageLocal = driveChartData.local.incSize[0];
const driveUsageRemote = driveChartData.remote.incSize[0];
const [ const [
notesCount,
originalNotesCount,
usersCount,
originalUsersCount,
reactionsCount, reactionsCount,
//originalReactionsCount, //originalReactionsCount,
instances, instances,
] = await Promise.all([ ] = await Promise.all([
Notes.count({ cache: 3600000 }), // 1 hour
Notes.count({ where: { userHost: IsNull() }, cache: 3600000 }),
Users.count({ cache: 3600000 }),
Users.count({ where: { host: IsNull() }, cache: 3600000 }),
NoteReactions.count({ cache: 3600000 }), // 1 hour NoteReactions.count({ cache: 3600000 }), // 1 hour
//NoteReactions.count({ where: { userHost: IsNull() }, cache: 3600000 }), //NoteReactions.count({ where: { userHost: IsNull() }, cache: 3600000 }),
Instances.count({ cache: 3600000 }), Instances.count({ cache: 3600000 }),
@ -86,7 +109,7 @@ export default define(meta, paramDef, async () => {
reactionsCount, reactionsCount,
//originalReactionsCount, //originalReactionsCount,
instances, instances,
driveUsageLocal: 0, driveUsageLocal,
driveUsageRemote: 0, driveUsageRemote,
}; };
}); });