perf(backend): createdAtをidから取得するように & 無駄なDateインスタンスの生成を避けるように

This commit is contained in:
syuilo
2023-10-16 10:45:22 +09:00
parent 15706c8c2b
commit 1fa1d31696
171 changed files with 442 additions and 537 deletions

View File

@@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { AccessTokensRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
requireCredential: true,
@@ -27,6 +28,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.accessTokensRepository)
private accessTokensRepository: AccessTokensRepository,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.accessTokensRepository.createQueryBuilder('token')
@@ -34,8 +37,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('token.app', 'app');
switch (ps.sort) {
case '+createdAt': query.orderBy('token.createdAt', 'DESC'); break;
case '-createdAt': query.orderBy('token.createdAt', 'ASC'); break;
case '+createdAt': query.orderBy('token.id', 'DESC'); break;
case '-createdAt': query.orderBy('token.id', 'ASC'); break;
case '+lastUsedAt': query.orderBy('token.lastUsedAt', 'DESC'); break;
case '-lastUsedAt': query.orderBy('token.lastUsedAt', 'ASC'); break;
default: query.orderBy('token.id', 'ASC'); break;
@@ -46,7 +49,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return await Promise.all(tokens.map(token => ({
id: token.id,
name: token.name ?? token.app?.name,
createdAt: token.createdAt,
createdAt: this.idService.parse(token.id).date.toISOString(),
lastUsedAt: token.lastUsedAt,
permission: token.permission,
})));

View File

@@ -53,8 +53,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
} else {
await this.registryItemsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
updatedAt: new Date(),
userId: me.id,
domain: null,

View File

@@ -63,8 +63,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const webhook = await this.webhooksRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
name: ps.name,
url: ps.url,