Merge branch 'develop' into fetch

This commit is contained in:
tamaina
2023-01-11 14:55:14 +00:00
106 changed files with 2020 additions and 1910 deletions

View File

@@ -0,0 +1,11 @@
export class PollChoiceLength1673336077243 {
name = 'PollChoiceLength1673336077243'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "poll" ALTER COLUMN "choices" TYPE character varying(256) array`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "poll" ALTER COLUMN "choices" TYPE character varying(128) array`);
}
}

View File

@@ -24,7 +24,7 @@ export class Poll {
public multiple: boolean;
@Column('varchar', {
length: 128, array: true, default: '{}',
length: 256, array: true, default: '{}',
})
public choices: string[];

View File

@@ -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 {

View File

@@ -3,6 +3,8 @@ import { IsNull } from 'typeorm';
import type { InstancesRepository, NoteReactionsRepository, NotesRepository, UsersRepository } from '@/models/index.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import NotesChart from '@/core/chart/charts/notes.js';
import UsersChart from '@/core/chart/charts/users.js';
export const meta = {
requireCredential: false,
@@ -66,21 +68,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
@Inject(DI.noteReactionsRepository)
private noteReactionsRepository: NoteReactionsRepository,
private notesChart: NotesChart,
private usersChart: UsersChart,
) {
super(meta, paramDef, async () => {
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];
const [
notesCount,
originalNotesCount,
usersCount,
originalUsersCount,
reactionsCount,
//originalReactionsCount,
instances,
] = await Promise.all([
this.notesRepository.count({ cache: 3600000 }), // 1 hour
this.notesRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
this.usersRepository.count({ cache: 3600000 }),
this.usersRepository.count({ where: { host: IsNull() }, cache: 3600000 }),
this.noteReactionsRepository.count({ cache: 3600000 }), // 1 hour
//this.noteReactionsRepository.count({ where: { userHost: IsNull() }, cache: 3600000 }),
this.instancesRepository.count({ cache: 3600000 }),