1
0
Fork 1
mirror of https://example.com synced 2024-11-22 12:26:38 +09:00

perf: cache stats (close #75)

This commit is contained in:
naskya 2023-09-17 08:04:22 +09:00
parent 14567b9ece
commit 3e663f975e
Signed by: naskya
GPG key ID: 164DFF24E2D40139

View file

@ -1,6 +1,7 @@
import { Instances, Notes, Users } from "@/models/index.js";
import define from "../define.js";
import { IsNull } from "typeorm";
import { Cache } from "@/misc/cache.js";
export const meta = {
requireCredential: false,
@ -60,7 +61,7 @@ export const paramDef = {
required: [],
} as const;
export default define(meta, paramDef, async () => {
const stats = async () => {
const [
notesCount,
originalNotesCount,
@ -107,4 +108,10 @@ export default define(meta, paramDef, async () => {
driveUsageLocal,
driveUsageRemote,
};
};
const cache = new Cache<Awaited<ReturnType<typeof stats>>>("stats", 60 * 10);
export default define(meta, paramDef, async () => {
return await cache.fetch(null, () => stats());
});