forked from naskya/firefish
perf: cache stats (close #75)
This commit is contained in:
parent
14567b9ece
commit
3e663f975e
1 changed files with 8 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { Instances, Notes, Users } from "@/models/index.js";
|
import { Instances, Notes, Users } from "@/models/index.js";
|
||||||
import define from "../define.js";
|
import define from "../define.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
|
import { Cache } from "@/misc/cache.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: false,
|
requireCredential: false,
|
||||||
|
@ -60,7 +61,7 @@ export const paramDef = {
|
||||||
required: [],
|
required: [],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async () => {
|
const stats = async () => {
|
||||||
const [
|
const [
|
||||||
notesCount,
|
notesCount,
|
||||||
originalNotesCount,
|
originalNotesCount,
|
||||||
|
@ -107,4 +108,10 @@ export default define(meta, paramDef, async () => {
|
||||||
driveUsageLocal,
|
driveUsageLocal,
|
||||||
driveUsageRemote,
|
driveUsageRemote,
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const cache = new Cache<Awaited<ReturnType<typeof stats>>>("stats", 60 * 10);
|
||||||
|
|
||||||
|
export default define(meta, paramDef, async () => {
|
||||||
|
return await cache.fetch(null, () => stats());
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue