summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-01-10 20:08:55 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-01-10 20:08:55 +0900
commitc5cfbd99d03c88038becfed9d99df5dbb175e154 (patch)
tree291fdd16c33dba13e2664b229ba3f5a814927542 /packages/backend/src
parentperf(server): improve stats api performance (diff)
downloadsharkey-c5cfbd99d03c88038becfed9d99df5dbb175e154.tar.gz
sharkey-c5cfbd99d03c88038becfed9d99df5dbb175e154.tar.bz2
sharkey-c5cfbd99d03c88038becfed9d99df5dbb175e154.zip
perf(server): improve nodeinfo performance
Resolve #9505
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/server/NodeinfoServerService.ts27
1 files changed, 19 insertions, 8 deletions
diff --git a/packages/backend/src/server/NodeinfoServerService.ts b/packages/backend/src/server/NodeinfoServerService.ts
index 86d87872b2..c4236c8752 100644
--- a/packages/backend/src/server/NodeinfoServerService.ts
+++ b/packages/backend/src/server/NodeinfoServerService.ts
@@ -8,6 +8,8 @@ import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { Cache } from '@/misc/cache.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
+import NotesChart from '@/core/chart/charts/notes.js';
+import UsersChart from '@/core/chart/charts/users.js';
import type { FastifyInstance, FastifyPluginOptions } from 'fastify';
const nodeinfo2_1path = '/nodeinfo/2.1';
@@ -27,6 +29,8 @@ export class NodeinfoServerService {
private userEntityService: UserEntityService,
private metaService: MetaService,
+ private notesChart: NotesChart,
+ private usersChart: UsersChart,
) {
//this.createServer = this.createServer.bind(this);
}
@@ -46,20 +50,27 @@ export class NodeinfoServerService {
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
const nodeinfo2 = async () => {
const now = Date.now();
+
+ const notesChart = await this.notesChart.getChart('hour', 1, null);
+ const localPosts = notesChart.local.total[0];
+
+ const usersChart = await this.usersChart.getChart('hour', 1, null);
+ const total = usersChart.local.total[0];
+
const [
meta,
- total,
- activeHalfyear,
- activeMonth,
- localPosts,
+ //activeHalfyear,
+ //activeMonth,
] = await Promise.all([
this.metaService.fetch(true),
- this.usersRepository.count({ where: { host: IsNull() } }),
- this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 15552000000)) } }),
- this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 2592000000)) } }),
- this.notesRepository.count({ where: { userHost: IsNull() } }),
+ // 重い
+ //this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 15552000000)) } }),
+ //this.usersRepository.count({ where: { host: IsNull(), lastActiveDate: MoreThan(new Date(now - 2592000000)) } }),
]);
+ const activeHalfyear = null;
+ const activeMonth = null;
+
const proxyAccount = meta.proxyAccountId ? await this.userEntityService.pack(meta.proxyAccountId).catch(() => null) : null;
return {