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

@ -128,8 +128,7 @@ export class SigninApiService {
const fail = async (status?: number, failure?: { id: string }) => {
// Append signin history
await this.signinsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: user.id,
ip: request.ip,
headers: request.headers as any,

View file

@ -30,8 +30,7 @@ export class SigninService {
setImmediate(async () => {
// Append signin history
const record = await this.signinsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: user.id,
ip: request.ip,
headers: request.headers as any,

View file

@ -164,8 +164,7 @@ export class SignupApiService {
const hash = await bcrypt.hash(password, salt);
const pendingUser = await this.userPendingsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
code,
email: emailAddress!,
username: username,

View file

@ -44,8 +44,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const ad = await this.adsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
expiresAt: new Date(ps.expiresAt),
startsAt: new Date(ps.startsAt),
dayOfWeek: ps.dayOfWeek,

View file

@ -71,7 +71,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const { raw, packed } = await this.announcementService.create({
createdAt: new Date(),
updatedAt: null,
title: ps.title,
text: ps.text,

View file

@ -9,6 +9,7 @@ import type { MiAnnouncement } from '@/models/Announcement.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
tags: ['admin'],
@ -81,6 +82,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private announcementReadsRepository: AnnouncementReadsRepository,
private queryService: QueryService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.announcementsRepository.createQueryBuilder('announcement'), ps.sinceId, ps.untilId);
@ -102,7 +104,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return announcements.map(announcement => ({
id: announcement.id,
createdAt: announcement.createdAt.toISOString(),
createdAt: this.idService.parse(announcement.id).date.toISOString(),
updatedAt: announcement.updatedAt?.toISOString() ?? null,
title: announcement.title,
text: announcement.text,

View file

@ -8,6 +8,7 @@ import type { DriveFilesRepository, UsersRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
import { IdService } from '@/core/IdService.js';
import { ApiError } from '../../../error.js';
export const meta = {
@ -163,6 +164,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private usersRepository: UsersRepository,
private roleService: RoleService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const file = ps.fileId ? await this.driveFilesRepository.findOneBy({ id: ps.fileId }) : await this.driveFilesRepository.findOne({
@ -212,7 +214,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
type: file.type,
name: file.name,
md5: file.md5,
createdAt: file.createdAt.toISOString(),
createdAt: this.idService.parse(file.id).date.toISOString(),
requestIp: iAmModerator ? file.requestIp : null,
requestHeaders: iAmModerator && !ownerIsModerator ? file.requestHeaders : null,
};

View file

@ -79,7 +79,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const copied = await this.emojisRepository.insert({
id: this.idService.genId(),
id: this.idService.gen(),
updatedAt: new Date(),
name: emoji.name,
host: null,

View file

@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
import type { UserIpsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
tags: ['admin'],
@ -28,17 +29,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.userIpsRepository)
private userIpsRepository: UserIpsRepository,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const ips = await this.userIpsRepository.find({
where: { userId: ps.userId },
order: { createdAt: 'DESC' },
order: { id: 'DESC' },
take: 30,
});
return ips.map(x => ({
ip: x.ip,
createdAt: x.createdAt.toISOString(),
createdAt: this.idService.parse(x.id).date.toISOString(),
}));
});
}

View file

@ -72,8 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
for (let i = 0; i < ps.count; i++) {
ticketsPromises.push(this.registrationTicketsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
expiresAt: ps.expiresAt ? new Date(ps.expiresAt) : null,
code: generateInviteCode(),
}).then(x => this.registrationTicketsRepository.findOneByOrFail(x.identifiers[0])));

View file

@ -10,6 +10,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { IdService } from '@/core/IdService.js';
import { ApiError } from '../../../error.js';
export const meta = {
@ -49,6 +50,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private userEntityService: UserEntityService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const role = await this.rolesRepository.findOneBy({
@ -74,7 +76,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return await Promise.all(assigns.map(async assign => ({
id: assign.id,
createdAt: assign.createdAt,
createdAt: this.idService.parse(assign.id).date.toISOString(),
user: await this.userEntityService.pack(assign.user!, me, { detail: true }),
expiresAt: assign.expiresAt,
})));

View file

@ -9,6 +9,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
import { RoleEntityService } from '@/core/entities/RoleEntityService.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
tags: ['admin'],
@ -44,6 +45,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private roleService: RoleService,
private roleEntityService: RoleEntityService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const [user, profile] = await Promise.all([
@ -92,7 +94,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
policies: await this.roleService.getUserPolicies(user.id),
roles: await this.roleEntityService.packMany(roles, me),
roleAssigns: roleAssigns.map(a => ({
createdAt: a.createdAt.toISOString(),
createdAt: this.idService.parse(a.id).date.toISOString(),
expiresAt: a.expiresAt ? a.expiresAt.toISOString() : null,
roleId: a.roleId,
})),

View file

@ -112,8 +112,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const now = new Date();
const antenna = await this.antennasRepository.insert({
id: this.idService.genId(),
createdAt: now,
id: this.idService.gen(now.getTime()),
lastUsedAt: now,
userId: me.id,
name: ps.name,

View file

@ -73,8 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const antenna = await this.antennasRepository.findOneBy({
id: ps.antennaId,

View file

@ -55,8 +55,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create account
const app = await this.appsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me ? me.id : null,
name: ps.name,
description: ps.description,

View file

@ -80,8 +80,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const now = new Date();
await this.accessTokensRepository.insert({
id: this.idService.genId(),
createdAt: now,
id: this.idService.gen(now.getTime()),
lastUsedAt: now,
appId: session.appId,
userId: me.id,

View file

@ -79,8 +79,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create session token document
const doc = await this.authSessionsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
appId: app.id,
token: token,
}).then(x => this.authSessionsRepository.findOneByOrFail(x.identifiers[0]));

View file

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

View file

@ -57,8 +57,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
await this.channelFavoritesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
channelId: channel.id,
});

View file

@ -57,8 +57,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
await this.channelFollowingsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
followerId: me.id,
followeeId: channel.id,
});

View file

@ -74,8 +74,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const isRangeSpecified = untilId != null && sinceId != null;
const channel = await this.channelsRepository.findOneBy({

View file

@ -74,8 +74,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
await this.clipFavoritesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
clipId: clip.id,
userId: me.id,
});

View file

@ -76,8 +76,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create folder
const folder = await this.driveFoldersRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
name: ps.name,
parentId: parent !== null ? parent.id : null,
userId: me.id,

View file

@ -53,9 +53,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const flash = await this.flashsRepository.insert({
id: this.idService.genId(),
id: this.idService.gen(),
userId: me.id,
createdAt: new Date(),
updatedAt: new Date(),
title: ps.title,
summary: ps.summary,

View file

@ -83,8 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create like
await this.flashLikesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
flashId: flash.id,
userId: me.id,
});

View file

@ -76,8 +76,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const post = await this.galleryPostsRepository.insert(new MiGalleryPost({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
updatedAt: new Date(),
title: ps.title,
description: ps.description,

View file

@ -83,8 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create like
await this.galleryLikesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
postId: post.id,
userId: me.id,
});

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,

View file

@ -62,7 +62,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (policies.inviteLimit) {
const count = await this.registrationTicketsRepository.countBy({
createdAt: MoreThan(new Date(Date.now() - (policies.inviteLimitCycle * 1000 * 60))),
id: MoreThan(this.idService.gen(Date.now() - (policies.inviteLimitCycle * 1000 * 60))),
createdById: me.id,
});
@ -72,8 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const ticket = await this.registrationTicketsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
createdBy: me,
createdById: me.id,
expiresAt: policies.inviteExpirationTime ? new Date(Date.now() + (policies.inviteExpirationTime * 1000 * 60)) : null,

View file

@ -9,6 +9,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import type { RegistrationTicketsRepository } from '@/models/_.js';
import { RoleService } from '@/core/RoleService.js';
import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
tags: ['meta'],
@ -41,12 +42,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private registrationTicketsRepository: RegistrationTicketsRepository,
private roleService: RoleService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me.id);
const count = policies.inviteLimit ? await this.registrationTicketsRepository.countBy({
createdAt: MoreThan(new Date(Date.now() - (policies.inviteExpirationTime * 60 * 1000))),
id: MoreThan(this.idService.gen(Date.now() - (policies.inviteExpirationTime * 60 * 1000))),
createdById: me.id,
}) : null;

View file

@ -59,8 +59,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Insert access token doc
await this.accessTokensRepository.insert({
id: this.idService.genId(),
createdAt: now,
id: this.idService.gen(now.getTime()),
lastUsedAt: now,
session: ps.session,
userId: me.id,

View file

@ -80,8 +80,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create favorite
await this.noteFavoritesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
noteId: note.id,
userId: me.id,
});

View file

@ -77,8 +77,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const policies = await this.roleService.getUserPolicies(me.id);
if (!policies.ltlAvailable) {

View file

@ -73,8 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
if (!policies.ltlAvailable) {

View file

@ -98,7 +98,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
id: In(polls.map(poll => poll.noteId)),
},
order: {
createdAt: 'DESC',
id: 'DESC',
},
});

View file

@ -145,8 +145,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create vote
const vote = await this.pollVotesRepository.insert({
id: this.idService.genId(),
createdAt,
id: this.idService.gen(createdAt.getTime()),
noteId: note.id,
userId: me.id,
choice: ps.choice,

View file

@ -72,8 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
await this.noteReadService.read(me.id, mutedNotes);
await this.noteThreadMutingsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
threadId: note.threadId ?? note.id,
userId: me.id,
});

View file

@ -66,8 +66,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const [
followings,

View file

@ -83,8 +83,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const list = await this.userListsRepository.findOneBy({
id: ps.listId,

View file

@ -103,8 +103,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
const page = await this.pagesRepository.insert(new MiPage({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
updatedAt: new Date(),
title: ps.title,
name: ps.name,

View file

@ -83,8 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create like
await this.pageLikesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
pageId: page.id,
userId: me.id,
});

View file

@ -60,8 +60,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
await this.promoReadsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
noteId: note.id,
userId: me.id,
});

View file

@ -90,8 +90,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Create mute
await this.renoteMutingsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
muterId: muter.id,
muteeId: mutee.id,
} as MiRenoteMuting);

View file

@ -84,8 +84,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const token = secureRndstr(64, { chars: L_CHARS });
await this.passwordResetRequestsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: profile.userId,
token,
});

View file

@ -8,6 +8,7 @@ import { Inject, Injectable } from '@nestjs/common';
import type { UserProfilesRepository, PasswordResetRequestsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js';
import { IdService } from '@/core/IdService.js';
export const meta = {
tags: ['reset password'],
@ -38,6 +39,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const req = await this.passwordResetRequestsRepository.findOneByOrFail({
@ -45,7 +48,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
// 発行してから30分以上経過していたら無効
if (Date.now() - req.createdAt.getTime() > 1000 * 60 * 30) {
if (Date.now() - this.idService.parse(req.id).date.getTime() > 1000 * 60 * 30) {
throw new Error(); // TODO
}

View file

@ -69,8 +69,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const role = await this.rolesRepository.findOneBy({
id: ps.roleId,

View file

@ -88,8 +88,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
await this.swSubscriptionsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
endpoint: ps.endpoint,
auth: ps.auth,

View file

@ -104,8 +104,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const userList = await this.userListsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
name: ps.name,
} as MiUserList).then(x => this.userListsRepository.findOneByOrFail(x.identifiers[0]));

View file

@ -66,8 +66,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const userList = await this.userListsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
name: ps.name,
} as MiUserList).then(x => this.userListsRepository.findOneByOrFail(x.identifiers[0]));

View file

@ -69,8 +69,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
await this.userListFavoritesRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
userId: me.id,
userListId: ps.listId,
});

View file

@ -74,8 +74,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private redisTimelineService: RedisTimelineService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.genId(new Date(ps.untilDate!)) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.genId(new Date(ps.sinceDate!)) : null);
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const isRangeSpecified = untilId != null && sinceId != null;
const isSelf = me && (me.id === ps.userId);

View file

@ -82,8 +82,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const report = await this.abuseUserReportsRepository.insert({
id: this.idService.genId(),
createdAt: new Date(),
id: this.idService.gen(),
targetUserId: user.id,
targetUserHost: user.host,
reporterId: me.id,

View file

@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!previousMemo) {
await this.userMemosRepository.insert({
id: this.idService.genId(),
id: this.idService.gen(),
userId: me.id,
targetUserId: target.id,
memo: ps.memo,

View file

@ -325,8 +325,7 @@ export class OAuth2ProviderService {
// NOTE: we don't have a setup for automatic token expiration
await accessTokensRepository.insert({
id: idService.genId(),
createdAt: now,
id: idService.gen(now.getTime()),
lastUsedAt: now,
userId: granted.userId,
token: accessToken,

View file

@ -13,6 +13,7 @@ import type { MiUser } from '@/models/User.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
import { bindThis } from '@/decorators.js';
import { IdService } from '@/core/IdService.js';
@Injectable()
export class FeedService {
@ -31,6 +32,7 @@ export class FeedService {
private userEntityService: UserEntityService,
private driveFileEntityService: DriveFileEntityService,
private idService: IdService,
) {
}
@ -49,14 +51,14 @@ export class FeedService {
renoteId: IsNull(),
visibility: In(['public', 'home']),
},
order: { createdAt: -1 },
order: { id: -1 },
take: 20,
});
const feed = new Feed({
id: author.link,
title: `${author.name} (@${user.username}@${this.config.host})`,
updated: notes[0].createdAt,
updated: this.idService.parse(notes[0].id).date,
generator: 'Misskey',
description: `${user.notesCount} Notes, ${profile.ffVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.ffVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
link: author.link,
@ -78,7 +80,7 @@ export class FeedService {
feed.addItem({
title: `New note by ${author.name}`,
link: `${this.config.url}/notes/${note.id}`,
date: note.createdAt,
date: this.idService.parse(note.id).date,
description: note.cw ?? undefined,
content: note.text ?? undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) ?? undefined : undefined,