From 24af7cccdc30df2c9b0db02e5665dd040bc0f58b Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 16 Aug 2023 08:36:11 +0900 Subject: [PATCH] wip --- packages/backend/src/core/AnnouncementService.ts | 14 +++++++------- packages/backend/src/core/CacheService.ts | 6 +++--- packages/backend/src/core/CustomEmojiService.ts | 6 +++--- packages/backend/src/core/GlobalEventService.ts | 4 ++-- packages/backend/src/core/PollService.ts | 4 ++-- .../backend/src/core/PushNotificationService.ts | 6 +++--- packages/backend/src/core/RoleService.ts | 16 ++++++++-------- packages/backend/src/core/SearchService.ts | 4 ++-- packages/backend/src/core/UserMutingService.ts | 4 ++-- .../core/activitypub/models/ApMentionService.ts | 8 ++++---- .../src/core/entities/ClipEntityService.ts | 6 +++--- .../src/core/entities/DriveFileEntityService.ts | 6 +++--- 12 files changed, 42 insertions(+), 42 deletions(-) diff --git a/packages/backend/src/core/AnnouncementService.ts b/packages/backend/src/core/AnnouncementService.ts index a6b411ad22..64e8ae758c 100644 --- a/packages/backend/src/core/AnnouncementService.ts +++ b/packages/backend/src/core/AnnouncementService.ts @@ -7,7 +7,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Brackets } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { MiUser } from '@/models/entities/User.js'; -import type { AnnouncementReadsRepository, AnnouncementsRepository, Announcement, AnnouncementRead } from '@/models/index.js'; +import type { AnnouncementReadsRepository, AnnouncementsRepository, MiAnnouncement, MiAnnouncementRead } from '@/models/index.js'; import { bindThis } from '@/decorators.js'; import { Packed } from '@/misc/json-schema.js'; import { IdService } from '@/core/IdService.js'; @@ -28,14 +28,14 @@ export class AnnouncementService { } @bindThis - public async getReads(userId: MiUser['id']): Promise { + public async getReads(userId: MiUser['id']): Promise { return this.announcementReadsRepository.findBy({ userId: userId, }); } @bindThis - public async getUnreadAnnouncements(user: MiUser): Promise { + public async getUnreadAnnouncements(user: MiUser): Promise { const readsQuery = this.announcementReadsRepository.createQueryBuilder('read') .select('read.announcementId') .where('read.userId = :userId', { userId: user.id }); @@ -58,7 +58,7 @@ export class AnnouncementService { } @bindThis - public async create(values: Partial): Promise<{ raw: Announcement; packed: Packed<'Announcement'> }> { + public async create(values: Partial): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> { const announcement = await this.announcementsRepository.insert({ id: this.idService.genId(), createdAt: new Date(), @@ -92,7 +92,7 @@ export class AnnouncementService { } @bindThis - public async read(user: MiUser, announcementId: Announcement['id']): Promise { + public async read(user: MiUser, announcementId: MiAnnouncement['id']): Promise { try { await this.announcementReadsRepository.insert({ id: this.idService.genId(), @@ -111,10 +111,10 @@ export class AnnouncementService { @bindThis public async packMany( - announcements: Announcement[], + announcements: MiAnnouncement[], me?: { id: MiUser['id'] } | null | undefined, options?: { - reads?: AnnouncementRead[]; + reads?: MiAnnouncementRead[]; }, ): Promise[]> { const reads = me ? (options?.reads ?? await this.getReads(me.id)) : []; diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts index 745118d9db..15be5f398c 100644 --- a/packages/backend/src/core/CacheService.ts +++ b/packages/backend/src/core/CacheService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; -import type { BlockingsRepository, ChannelFollowingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, UserProfile, UserProfilesRepository, UsersRepository } from '@/models/index.js'; +import type { BlockingsRepository, ChannelFollowingsRepository, FollowingsRepository, MutingsRepository, RenoteMutingsRepository, MiUserProfile, UserProfilesRepository, UsersRepository } from '@/models/index.js'; import { MemoryKVCache, RedisKVCache } from '@/misc/cache.js'; import type { MiLocalUser, MiUser } from '@/models/entities/User.js'; import { DI } from '@/di-symbols.js'; @@ -20,7 +20,7 @@ export class CacheService implements OnApplicationShutdown { public localUserByNativeTokenCache: MemoryKVCache; public localUserByIdCache: MemoryKVCache; public uriPersonCache: MemoryKVCache; - public userProfileCache: RedisKVCache; + public userProfileCache: RedisKVCache; public userMutingsCache: RedisKVCache>; public userBlockingCache: RedisKVCache>; public userBlockedCache: RedisKVCache>; // NOTE: 「被」Blockキャッシュ @@ -96,7 +96,7 @@ export class CacheService implements OnApplicationShutdown { fromMapConverter: id => id === null ? null : userByIdCache.get(id), }); - this.userProfileCache = new RedisKVCache(this.redisClient, 'userProfile', { + this.userProfileCache = new RedisKVCache(this.redisClient, 'userProfile', { lifetime: 1000 * 60 * 30, // 30m memoryCacheLifetime: 1000 * 60, // 1m fetcher: (key) => this.userProfilesRepository.findOneByOrFail({ userId: key }), diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts index eb909f81cd..8fd993345b 100644 --- a/packages/backend/src/core/CustomEmojiService.ts +++ b/packages/backend/src/core/CustomEmojiService.ts @@ -12,7 +12,7 @@ import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js'; import { GlobalEventService } from '@/core/GlobalEventService.js'; import type { MiDriveFile } from '@/models/entities/DriveFile.js'; import type { MiEmoji } from '@/models/entities/Emoji.js'; -import type { EmojisRepository, Role } from '@/models/index.js'; +import type { EmojisRepository, MiRole } from '@/models/index.js'; import { bindThis } from '@/decorators.js'; import { MemoryKVCache, RedisSingleCache } from '@/misc/cache.js'; import { UtilityService } from '@/core/UtilityService.js'; @@ -65,7 +65,7 @@ export class CustomEmojiService implements OnApplicationShutdown { license: string | null; isSensitive: boolean; localOnly: boolean; - roleIdsThatCanBeUsedThisEmojiAsReaction: Role['id'][]; + roleIdsThatCanBeUsedThisEmojiAsReaction: MiRole['id'][]; }): Promise { const emoji = await this.emojisRepository.insert({ id: this.idService.genId(), @@ -103,7 +103,7 @@ export class CustomEmojiService implements OnApplicationShutdown { license?: string | null; isSensitive?: boolean; localOnly?: boolean; - roleIdsThatCanBeUsedThisEmojiAsReaction?: Role['id'][]; + roleIdsThatCanBeUsedThisEmojiAsReaction?: MiRole['id'][]; }): Promise { const emoji = await this.emojisRepository.findOneByOrFail({ id: id }); const sameNameEmoji = await this.emojisRepository.findOneBy({ name: data.name, host: IsNull() }); diff --git a/packages/backend/src/core/GlobalEventService.ts b/packages/backend/src/core/GlobalEventService.ts index e4b0ad9dc6..224eb3c599 100644 --- a/packages/backend/src/core/GlobalEventService.ts +++ b/packages/backend/src/core/GlobalEventService.ts @@ -25,7 +25,7 @@ import type { Packed } from '@/misc/json-schema.js'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { bindThis } from '@/decorators.js'; -import { Role } from '@/models/index.js'; +import { MiRole } from '@/models/index.js'; @Injectable() export class GlobalEventService { @@ -89,7 +89,7 @@ export class GlobalEventService { } @bindThis - public publishRoleTimelineStream(roleId: Role['id'], type: K, value?: RoleTimelineStreamTypes[K]): void { + public publishRoleTimelineStream(roleId: MiRole['id'], type: K, value?: RoleTimelineStreamTypes[K]): void { this.publish(`roleTimelineStream:${roleId}`, type, typeof value === 'undefined' ? null : value); } diff --git a/packages/backend/src/core/PollService.ts b/packages/backend/src/core/PollService.ts index 4f67d2f938..551c779769 100644 --- a/packages/backend/src/core/PollService.ts +++ b/packages/backend/src/core/PollService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; -import type { NotesRepository, UsersRepository, PollsRepository, PollVotesRepository, User } from '@/models/index.js'; +import type { NotesRepository, UsersRepository, PollsRepository, PollVotesRepository, MiUser } from '@/models/index.js'; import type { MiNote } from '@/models/entities/Note.js'; import { RelayService } from '@/core/RelayService.js'; import { IdService } from '@/core/IdService.js'; @@ -42,7 +42,7 @@ export class PollService { } @bindThis - public async vote(user: User, note: MiNote, choice: number) { + public async vote(user: MiUser, note: MiNote, choice: number) { const poll = await this.pollsRepository.findOneBy({ noteId: note.id }); if (poll == null) throw new Error('poll not found'); diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts index d5a727b3e4..93928e3cd7 100644 --- a/packages/backend/src/core/PushNotificationService.ts +++ b/packages/backend/src/core/PushNotificationService.ts @@ -10,7 +10,7 @@ import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import type { Packed } from '@/misc/json-schema.js'; import { getNoteSummary } from '@/misc/get-note-summary.js'; -import type { SwSubscription, SwSubscriptionsRepository } from '@/models/index.js'; +import type { MiSwSubscription, SwSubscriptionsRepository } from '@/models/index.js'; import { MetaService } from '@/core/MetaService.js'; import { bindThis } from '@/decorators.js'; import { RedisKVCache } from '@/misc/cache.js'; @@ -48,7 +48,7 @@ function truncateBody(type: T, body: Pus @Injectable() export class PushNotificationService implements OnApplicationShutdown { - private subscriptionsCache: RedisKVCache; + private subscriptionsCache: RedisKVCache; constructor( @Inject(DI.config) @@ -62,7 +62,7 @@ export class PushNotificationService implements OnApplicationShutdown { private metaService: MetaService, ) { - this.subscriptionsCache = new RedisKVCache(this.redisClient, 'userSwSubscriptions', { + this.subscriptionsCache = new RedisKVCache(this.redisClient, 'userSwSubscriptions', { lifetime: 1000 * 60 * 60 * 1, // 1h memoryCacheLifetime: 1000 * 60 * 3, // 3m fetcher: (key) => this.swSubscriptionsRepository.findBy({ userId: key }), diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index a8d1be25a0..f755f3ecfb 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -6,7 +6,7 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; import { In } from 'typeorm'; -import type { Role, RoleAssignment, RoleAssignmentsRepository, RolesRepository, UsersRepository } from '@/models/index.js'; +import type { MiRole, MiRoleAssignment, RoleAssignmentsRepository, RolesRepository, UsersRepository } from '@/models/index.js'; import { MemoryKVCache, MemorySingleCache } from '@/misc/cache.js'; import type { MiUser } from '@/models/entities/User.js'; import { DI } from '@/di-symbols.js'; @@ -71,8 +71,8 @@ export const DEFAULT_POLICIES: RolePolicies = { @Injectable() export class RoleService implements OnApplicationShutdown { - private rolesCache: MemorySingleCache; - private roleAssignmentByUserIdCache: MemoryKVCache; + private rolesCache: MemorySingleCache; + private roleAssignmentByUserIdCache: MemoryKVCache; public static AlreadyAssignedError = class extends Error {}; public static NotAssignedError = class extends Error {}; @@ -101,8 +101,8 @@ export class RoleService implements OnApplicationShutdown { ) { //this.onMessage = this.onMessage.bind(this); - this.rolesCache = new MemorySingleCache(1000 * 60 * 60 * 1); - this.roleAssignmentByUserIdCache = new MemoryKVCache(1000 * 60 * 60 * 1); + this.rolesCache = new MemorySingleCache(1000 * 60 * 60 * 1); + this.roleAssignmentByUserIdCache = new MemoryKVCache(1000 * 60 * 60 * 1); this.redisForSub.on('message', this.onMessage); } @@ -326,7 +326,7 @@ export class RoleService implements OnApplicationShutdown { } @bindThis - public async isExplorable(role: { id: Role['id']} | null): Promise { + public async isExplorable(role: { id: MiRole['id']} | null): Promise { if (role == null) return false; const check = await this.rolesRepository.findOneBy({ id: role.id }); if (check == null) return false; @@ -374,7 +374,7 @@ export class RoleService implements OnApplicationShutdown { } @bindThis - public async assign(userId: MiUser['id'], roleId: Role['id'], expiresAt: Date | null = null): Promise { + public async assign(userId: MiUser['id'], roleId: MiRole['id'], expiresAt: Date | null = null): Promise { const now = new Date(); const existing = await this.roleAssignmentsRepository.findOneBy({ @@ -409,7 +409,7 @@ export class RoleService implements OnApplicationShutdown { } @bindThis - public async unassign(userId: MiUser['id'], roleId: Role['id']): Promise { + public async unassign(userId: MiUser['id'], roleId: MiRole['id']): Promise { const now = new Date(); const existing = await this.roleAssignmentsRepository.findOneBy({ roleId, userId }); diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 6295cbb9c0..ce80744c6d 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -9,7 +9,7 @@ import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { bindThis } from '@/decorators.js'; import { MiNote } from '@/models/entities/Note.js'; -import { User } from '@/models/index.js'; +import { MiUser } from '@/models/index.js'; import type { NotesRepository } from '@/models/index.js'; import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; import { QueryService } from '@/core/QueryService.js'; @@ -150,7 +150,7 @@ export class SearchService { } @bindThis - public async searchNote(q: string, me: User | null, opts: { + public async searchNote(q: string, me: MiUser | null, opts: { userId?: MiNote['userId'] | null; channelId?: MiNote['channelId'] | null; host?: string | null; diff --git a/packages/backend/src/core/UserMutingService.ts b/packages/backend/src/core/UserMutingService.ts index 1f0cc14695..1f0b2c215b 100644 --- a/packages/backend/src/core/UserMutingService.ts +++ b/packages/backend/src/core/UserMutingService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { In } from 'typeorm'; -import type { MutingsRepository, Muting } from '@/models/index.js'; +import type { MutingsRepository, MiMuting } from '@/models/index.js'; import { IdService } from '@/core/IdService.js'; import type { MiUser } from '@/models/entities/User.js'; import { DI } from '@/di-symbols.js'; @@ -37,7 +37,7 @@ export class UserMutingService { } @bindThis - public async unmute(mutings: Muting[]): Promise { + public async unmute(mutings: MiMuting[]): Promise { if (mutings.length === 0) return; await this.mutingsRepository.delete({ diff --git a/packages/backend/src/core/activitypub/models/ApMentionService.ts b/packages/backend/src/core/activitypub/models/ApMentionService.ts index ead2b38c22..f4045301de 100644 --- a/packages/backend/src/core/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/activitypub/models/ApMentionService.ts @@ -5,7 +5,7 @@ import { Injectable } from '@nestjs/common'; import promiseLimit from 'promise-limit'; -import type { User } from '@/models/index.js'; +import type { MiUser } from '@/models/index.js'; import { toArray, unique } from '@/misc/prelude/array.js'; import { bindThis } from '@/decorators.js'; import { isMention } from '../type.js'; @@ -21,13 +21,13 @@ export class ApMentionService { } @bindThis - public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver): Promise { + public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver): Promise { const hrefs = unique(this.extractApMentionObjects(tags).map(x => x.href)); - const limit = promiseLimit(2); + const limit = promiseLimit(2); const mentionedUsers = (await Promise.all( hrefs.map(x => limit(() => this.apPersonService.resolvePerson(x, resolver).catch(() => null))), - )).filter((x): x is User => x != null); + )).filter((x): x is MiUser => x != null); return mentionedUsers; } diff --git a/packages/backend/src/core/entities/ClipEntityService.ts b/packages/backend/src/core/entities/ClipEntityService.ts index 24d6814322..63619ac9d3 100644 --- a/packages/backend/src/core/entities/ClipEntityService.ts +++ b/packages/backend/src/core/entities/ClipEntityService.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { DI } from '@/di-symbols.js'; -import type { ClipFavoritesRepository, ClipsRepository, User } from '@/models/index.js'; +import type { ClipFavoritesRepository, ClipsRepository, MiUser } from '@/models/index.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; import type { } from '@/models/entities/Blocking.js'; @@ -29,7 +29,7 @@ export class ClipEntityService { @bindThis public async pack( src: MiClip['id'] | MiClip, - me?: { id: User['id'] } | null | undefined, + me?: { id: MiUser['id'] } | null | undefined, ): Promise> { const meId = me ? me.id : null; const clip = typeof src === 'object' ? src : await this.clipsRepository.findOneByOrFail({ id: src }); @@ -51,7 +51,7 @@ export class ClipEntityService { @bindThis public packMany( clips: MiClip[], - me?: { id: User['id'] } | null | undefined, + me?: { id: MiUser['id'] } | null | undefined, ) { return Promise.all(clips.map(x => this.pack(x, me))); } diff --git a/packages/backend/src/core/entities/DriveFileEntityService.ts b/packages/backend/src/core/entities/DriveFileEntityService.ts index 32861eaede..a09de58b4f 100644 --- a/packages/backend/src/core/entities/DriveFileEntityService.ts +++ b/packages/backend/src/core/entities/DriveFileEntityService.ts @@ -14,6 +14,9 @@ import type { MiUser } from '@/models/entities/User.js'; import type { MiDriveFile } from '@/models/entities/DriveFile.js'; import { appendQuery, query } from '@/misc/prelude/url.js'; import { deepClone } from '@/misc/clone.js'; +import { bindThis } from '@/decorators.js'; +import { isMimeImage } from '@/misc/is-mime-image.js'; +import { isNotNull } from '@/misc/is-not-null.js'; import { UtilityService } from '../UtilityService.js'; import { VideoProcessingService } from '../VideoProcessingService.js'; import { UserEntityService } from './UserEntityService.js'; @@ -24,9 +27,6 @@ type PackOptions = { self?: boolean, withUser?: boolean, }; -import { bindThis } from '@/decorators.js'; -import { isMimeImage } from '@/misc/is-mime-image.js'; -import { isNotNull } from '@/misc/is-not-null.js'; @Injectable() export class DriveFileEntityService {