2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-08-05 03:33:00 +02:00
|
|
|
import type { InstancesRepository, NoteReactionsRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-01-10 12:06:25 +01:00
|
|
|
import NotesChart from '@/core/chart/charts/notes.js';
|
|
|
|
import UsersChart from '@/core/chart/charts/users.js';
|
2017-08-12 08:17:03 +02:00
|
|
|
|
2018-11-02 05:47:44 +01:00
|
|
|
export const meta = {
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: false,
|
2018-11-02 05:47:44 +01:00
|
|
|
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['meta'],
|
|
|
|
|
2019-02-24 19:30:22 +01:00
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
properties: {
|
|
|
|
notesCount: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
},
|
|
|
|
originalNotesCount: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
},
|
|
|
|
usersCount: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
},
|
|
|
|
originalUsersCount: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
},
|
|
|
|
instances: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:30:22 +01:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
driveUsageLocal: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
driveUsageRemote: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2018-11-02 05:47:44 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
2023-08-17 14:20:58 +02:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
|
|
|
|
|
|
|
@Inject(DI.noteReactionsRepository)
|
|
|
|
private noteReactionsRepository: NoteReactionsRepository,
|
2023-01-10 12:06:25 +01:00
|
|
|
|
|
|
|
private notesChart: NotesChart,
|
|
|
|
private usersChart: UsersChart,
|
2022-09-17 20:27:08 +02:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async () => {
|
2023-01-10 12:06:25 +01:00
|
|
|
const notesChart = await this.notesChart.getChart('hour', 1, null);
|
|
|
|
const notesCount = notesChart.local.total[0] + notesChart.remote.total[0];
|
|
|
|
const originalNotesCount = notesChart.local.total[0];
|
|
|
|
|
|
|
|
const usersChart = await this.usersChart.getChart('hour', 1, null);
|
|
|
|
const usersCount = usersChart.local.total[0] + usersChart.remote.total[0];
|
|
|
|
const originalUsersCount = usersChart.local.total[0];
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const [
|
|
|
|
reactionsCount,
|
|
|
|
//originalReactionsCount,
|
|
|
|
instances,
|
|
|
|
] = await Promise.all([
|
|
|
|
this.noteReactionsRepository.count({ cache: 3600000 }), // 1 hour
|
|
|
|
//this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
|
|
|
|
this.instancesRepository.count({ cache: 3600000 }),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return {
|
|
|
|
notesCount,
|
|
|
|
originalNotesCount,
|
|
|
|
usersCount,
|
|
|
|
originalUsersCount,
|
|
|
|
reactionsCount,
|
|
|
|
//originalReactionsCount,
|
|
|
|
instances,
|
|
|
|
driveUsageLocal: 0,
|
|
|
|
driveUsageRemote: 0,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|