Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor: prefix Mi for all entities (misskey-dev#11719) (MisskeyIO#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
nafu-at committed Aug 28, 2023
1 parent 3a64b12 commit f93452c
Show file tree
Hide file tree
Showing 232 changed files with 2,046 additions and 2,049 deletions.
22 changes: 11 additions & 11 deletions packages/backend/src/core/AccountMoveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { IsNull, In, MoreThan, Not } from 'typeorm';
import { bindThis } from '@/decorators.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { LocalUser, RemoteUser, User } from '@/models/entities/User.js';
import type { BlockingsRepository, FollowingsRepository, InstancesRepository, Muting, MutingsRepository, UserListJoiningsRepository, UsersRepository } from '@/models/index.js';
import type { MiLocalUser, MiRemoteUser, MiUser } from '@/models/entities/User.js';
import type { BlockingsRepository, FollowingsRepository, InstancesRepository, MiMuting, MutingsRepository, UserListJoiningsRepository, UsersRepository } from '@/models/index.js';
import type { RelationshipJobData, ThinUser } from '@/queue/types.js';

import { IdService } from '@/core/IdService.js';
Expand Down Expand Up @@ -75,12 +75,12 @@ export class AccountMoveService {
* After delivering Move activity, its local followers unfollow the old account and then follow the new one.
*/
@bindThis
public async moveFromLocal(src: LocalUser, dst: LocalUser | RemoteUser): Promise<unknown> {
public async moveFromLocal(src: MiLocalUser, dst: MiLocalUser | MiRemoteUser): Promise<unknown> {
const srcUri = this.userEntityService.getUserUri(src);
const dstUri = this.userEntityService.getUserUri(dst);

// add movedToUri to indicate that the user has moved
const update = {} as Partial<LocalUser>;
const update = {} as Partial<MiLocalUser>;
update.alsoKnownAs = src.alsoKnownAs?.includes(dstUri) ? src.alsoKnownAs : src.alsoKnownAs?.concat([dstUri]) ?? [dstUri];
update.movedToUri = dstUri;
update.movedAt = new Date();
Expand Down Expand Up @@ -118,7 +118,7 @@ export class AccountMoveService {
}

@bindThis
public async postMoveProcess(src: User, dst: User): Promise<void> {
public async postMoveProcess(src: MiUser, dst: MiUser): Promise<void> {
// Copy blockings and mutings, and update lists
try {
await Promise.all([
Expand Down Expand Up @@ -217,7 +217,7 @@ export class AccountMoveService {
* @returns Promise<void>
*/
@bindThis
public async updateLists(src: ThinUser, dst: User): Promise<void> {
public async updateLists(src: ThinUser, dst: MiUser): Promise<void> {
// Return if there is no list to be updated.
const oldJoinings = await this.userListJoiningsRepository.find({
where: {
Expand Down Expand Up @@ -264,7 +264,7 @@ export class AccountMoveService {
}

@bindThis
private async adjustFollowingCounts(localFollowerIds: string[], oldAccount: User): Promise<void> {
private async adjustFollowingCounts(localFollowerIds: string[], oldAccount: MiUser): Promise<void> {
if (localFollowerIds.length === 0) return;

// Set the old account's following and followers counts to 0.
Expand Down Expand Up @@ -305,11 +305,11 @@ export class AccountMoveService {
*/
@bindThis
public async validateAlsoKnownAs(
dst: LocalUser | RemoteUser,
check: (oldUser: LocalUser | RemoteUser | null, newUser: LocalUser | RemoteUser) => boolean | Promise<boolean> = () => true,
dst: MiLocalUser | MiRemoteUser,
check: (oldUser: MiLocalUser | MiRemoteUser | null, newUser: MiLocalUser | MiRemoteUser) => boolean | Promise<boolean> = () => true,
instant = false,
): Promise<LocalUser | RemoteUser | null> {
let resultUser: LocalUser | RemoteUser | null = null;
): Promise<MiLocalUser | MiRemoteUser | null> {
let resultUser: MiLocalUser | MiRemoteUser | null = null;

if (this.userEntityService.isRemoteUser(dst)) {
if ((new Date()).getTime() - (dst.lastFetchedAt?.getTime() ?? 0) > 10 * 1000) {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/AccountUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import type { UsersRepository } from '@/models/index.js';
import type { Config } from '@/config.js';
import type { User } from '@/models/entities/User.js';
import type { MiUser } from '@/models/entities/User.js';
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { RelayService } from '@/core/RelayService.js';
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
Expand All @@ -31,7 +31,7 @@ export class AccountUpdateService {
}

@bindThis
public async publishToFollowers(userId: User['id']) {
public async publishToFollowers(userId: MiUser['id']) {
const user = await this.usersRepository.findOneBy({ id: userId });
if (user == null) throw new Error('user not found');

Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/AchievementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Inject, Injectable } from '@nestjs/common';
import type { UserProfilesRepository, UsersRepository } from '@/models/index.js';
import type { User } from '@/models/entities/User.js';
import type { MiUser } from '@/models/entities/User.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { NotificationService } from '@/core/NotificationService.js';
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AchievementService {

@bindThis
public async create(
userId: User['id'],
userId: MiUser['id'],
type: typeof ACHIEVEMENT_TYPES[number],
): Promise<void> {
if (!ACHIEVEMENT_TYPES.includes(type)) return;
Expand Down
42 changes: 21 additions & 21 deletions packages/backend/src/core/AnnouncementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { Inject, Injectable } from '@nestjs/common';
import { Brackets, In } from 'typeorm';
import type { AnnouncementReadsRepository, AnnouncementsRepository, UsersRepository } from '@/models/index.js';
import type { User } from '@/models/entities/User.js';
import { Announcement, AnnouncementRead } from '@/models/index.js';
import type { MiUser } from '@/models/entities/User.js';
import { MiAnnouncement, MiAnnouncementRead } from '@/models/index.js';
import { AnnouncementEntityService } from '@/core/entities/AnnouncementEntityService.js';
import { bindThis } from '@/decorators.js';
import { DI } from '@/di-symbols.js';
Expand Down Expand Up @@ -36,8 +36,8 @@ export class AnnouncementService {

@bindThis
public async create(
values: Partial<Announcement>,
): Promise<{ raw: Announcement; packed: Packed<'Announcement'> }> {
values: Partial<MiAnnouncement>,
): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
const announcement = await this.announcementsRepository
.insert({
id: this.idService.genId(),
Expand Down Expand Up @@ -85,11 +85,11 @@ export class AnnouncementService {

@bindThis
public async list(
userId: User['id'] | null,
userId: MiUser['id'] | null,
limit: number,
offset: number,
moderator: User,
): Promise<(Announcement & { userInfo: Packed<'UserLite'> | null, readCount: number })[]> {
moderator: MiUser,
): Promise<(MiAnnouncement & { userInfo: Packed<'UserLite'> | null, readCount: number })[]> {
const query = this.announcementsRepository.createQueryBuilder('announcement');
if (userId) {
query.andWhere('announcement."userId" = :userId', { userId: userId });
Expand All @@ -107,7 +107,7 @@ export class AnnouncementService {
.offset(offset)
.getMany();

const reads = new Map<Announcement, number>();
const reads = new Map<MiAnnouncement, number>();

for (const announcement of announcements) {
reads.set(announcement, await this.announcementReadsRepository.countBy({
Expand All @@ -131,9 +131,9 @@ export class AnnouncementService {

@bindThis
public async update(
announcementId: Announcement['id'],
values: Partial<Announcement>,
): Promise<{ raw: Announcement; packed: Packed<'Announcement'> }> {
announcementId: MiAnnouncement['id'],
values: Partial<MiAnnouncement>,
): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
const oldAnnouncement = await this.announcementsRepository.findOneByOrFail({
id: announcementId,
});
Expand Down Expand Up @@ -190,7 +190,7 @@ export class AnnouncementService {
}

@bindThis
public async delete(announcementId: Announcement['id']): Promise<void> {
public async delete(announcementId: MiAnnouncement['id']): Promise<void> {
await this.announcementReadsRepository.delete({
announcementId: announcementId,
});
Expand All @@ -199,15 +199,15 @@ export class AnnouncementService {

@bindThis
public async getAnnouncements(
me: User | null,
me: MiUser | null,
limit: number,
offset: number,
isActive?: boolean,
): Promise<Packed<'Announcement'>[]> {
const query = this.announcementsRepository.createQueryBuilder('announcement');
if (me) {
query.leftJoin(
AnnouncementRead,
MiAnnouncementRead,
'read',
'read."announcementId" = announcement.id AND read."userId" = :userId',
{ userId: me.id },
Expand Down Expand Up @@ -256,16 +256,16 @@ export class AnnouncementService {
await query
.limit(limit)
.offset(offset)
.getRawMany<Announcement & { isRead?: boolean | null }>(),
.getRawMany<MiAnnouncement & { isRead?: boolean | null }>(),
me,
);
}

@bindThis
public async getUnreadAnnouncements(me: User): Promise<Packed<'Announcement'>[]> {
public async getUnreadAnnouncements(me: MiUser): Promise<Packed<'Announcement'>[]> {
const query = this.announcementsRepository.createQueryBuilder('announcement');
query.leftJoinAndSelect(
AnnouncementRead,
MiAnnouncementRead,
'read',
'read."announcementId" = announcement.id AND read."userId" = :userId',
{ userId: me.id },
Expand Down Expand Up @@ -301,10 +301,10 @@ export class AnnouncementService {
}

@bindThis
public async countUnreadAnnouncements(me: User): Promise<number> {
public async countUnreadAnnouncements(me: MiUser): Promise<number> {
const query = this.announcementsRepository.createQueryBuilder('announcement');
query.leftJoinAndSelect(
AnnouncementRead,
MiAnnouncementRead,
'read',
'read."announcementId" = announcement.id AND read."userId" = :userId',
{ userId: me.id },
Expand Down Expand Up @@ -333,8 +333,8 @@ export class AnnouncementService {

@bindThis
public async markAsRead(
me: User,
announcementId: Announcement['id'],
me: MiUser,
announcementId: MiAnnouncement['id'],
): Promise<void> {
try {
await this.announcementReadsRepository.insert({
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import { Inject, Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';
import type { Antenna } from '@/models/entities/Antenna.js';
import type { Note } from '@/models/entities/Note.js';
import type { User } from '@/models/entities/User.js';
import type { MiAntenna } from '@/models/entities/Antenna.js';
import type { MiNote } from '@/models/entities/Note.js';
import type { MiUser } from '@/models/entities/User.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { AntennaEntityService } from '@/core/entities/AntennaEntityService.js';
import { IdService } from '@/core/IdService.js';
Expand All @@ -26,7 +26,7 @@ import type { OnApplicationShutdown } from '@nestjs/common';
@Injectable()
export class AntennaService implements OnApplicationShutdown {
private antennasFetched: boolean;
private antennas: Antenna[];
private antennas: MiAntenna[];

constructor(
@Inject(DI.redis)
Expand Down Expand Up @@ -91,7 +91,7 @@ export class AntennaService implements OnApplicationShutdown {
}

@bindThis
public async addNoteToAntennas(note: Note, noteUser: { id: User['id']; username: string; host: string | null; }): Promise<void> {
public async addNoteToAntennas(note: MiNote, noteUser: { id: MiUser['id']; username: string; host: string | null; }): Promise<void> {
const antennas = await this.getAntennas();
const antennasWithMatchResult = await Promise.all(antennas.map(antenna => this.checkHitAntenna(antenna, note, noteUser).then(hit => [antenna, hit] as const)));
const matchedAntennas = antennasWithMatchResult.filter(([, hit]) => hit).map(([antenna]) => antenna);
Expand All @@ -114,7 +114,7 @@ export class AntennaService implements OnApplicationShutdown {
// NOTE: フォローしているユーザーのノート、リストのユーザーのノート、グループのユーザーのノート指定はパフォーマンス上の理由で無効になっている

@bindThis
public async checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { id: User['id']; username: string; host: string | null; }): Promise<boolean> {
public async checkHitAntenna(antenna: MiAntenna, note: (MiNote | Packed<'Note'>), noteUser: { id: MiUser['id']; username: string; host: string | null; }): Promise<boolean> {
if (note.visibility === 'specified') return false;
if (note.visibility === 'followers') return false;

Expand Down
30 changes: 15 additions & 15 deletions packages/backend/src/core/CacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

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 { LocalUser, User } from '@/models/entities/User.js';
import type { MiLocalUser, MiUser } from '@/models/entities/User.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
Expand All @@ -16,11 +16,11 @@ import type { OnApplicationShutdown } from '@nestjs/common';

@Injectable()
export class CacheService implements OnApplicationShutdown {
public userByIdCache: MemoryKVCache<User, User | string>;
public localUserByNativeTokenCache: MemoryKVCache<LocalUser | null, string | null>;
public localUserByIdCache: MemoryKVCache<LocalUser>;
public uriPersonCache: MemoryKVCache<User | null, string | null>;
public userProfileCache: RedisKVCache<UserProfile>;
public userByIdCache: MemoryKVCache<MiUser, MiUser | string>;
public localUserByNativeTokenCache: MemoryKVCache<MiLocalUser | null, string | null>;
public localUserByIdCache: MemoryKVCache<MiLocalUser>;
public uriPersonCache: MemoryKVCache<MiUser | null, string | null>;
public userProfileCache: RedisKVCache<MiUserProfile>;
public userMutingsCache: RedisKVCache<Set<string>>;
public userBlockingCache: RedisKVCache<Set<string>>;
public userBlockedCache: RedisKVCache<Set<string>>; // NOTE: 「被」Blockキャッシュ
Expand Down Expand Up @@ -60,14 +60,14 @@ export class CacheService implements OnApplicationShutdown {
) {
//this.onMessage = this.onMessage.bind(this);

const localUserByIdCache = new MemoryKVCache<LocalUser>(1000 * 60 * 60 * 6 /* 6h */);
const localUserByIdCache = new MemoryKVCache<MiLocalUser>(1000 * 60 * 60 * 6 /* 6h */);
this.localUserByIdCache = localUserByIdCache;

// ローカルユーザーならlocalUserByIdCacheにデータを追加し、こちらにはid(文字列)だけを追加する
const userByIdCache = new MemoryKVCache<User, User | string>(1000 * 60 * 60 * 6 /* 6h */, {
const userByIdCache = new MemoryKVCache<MiUser, MiUser | string>(1000 * 60 * 60 * 6 /* 6h */, {
toMapConverter: user => {
if (user.host === null) {
localUserByIdCache.set(user.id, user as LocalUser);
localUserByIdCache.set(user.id, user as MiLocalUser);
return user.id;
}

Expand All @@ -77,7 +77,7 @@ export class CacheService implements OnApplicationShutdown {
});
this.userByIdCache = userByIdCache;

this.localUserByNativeTokenCache = new MemoryKVCache<LocalUser | null, string | null>(Infinity, {
this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null, string | null>(Infinity, {
toMapConverter: user => {
if (user === null) return null;

Expand All @@ -86,7 +86,7 @@ export class CacheService implements OnApplicationShutdown {
},
fromMapConverter: id => id === null ? null : localUserByIdCache.get(id),
});
this.uriPersonCache = new MemoryKVCache<User | null, string | null>(Infinity, {
this.uriPersonCache = new MemoryKVCache<MiUser | null, string | null>(Infinity, {
toMapConverter: user => {
if (user === null) return null;

Expand All @@ -96,7 +96,7 @@ export class CacheService implements OnApplicationShutdown {
fromMapConverter: id => id === null ? null : userByIdCache.get(id),
});

this.userProfileCache = new RedisKVCache<UserProfile>(this.redisClient, 'userProfile', {
this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', {
lifetime: 1000 * 60 * 30, // 30m
memoryCacheLifetime: 1000 * 60, // 1m
fetcher: (key) => this.userProfilesRepository.findOneByOrFail({ userId: key }),
Expand Down Expand Up @@ -178,7 +178,7 @@ export class CacheService implements OnApplicationShutdown {
break;
}
case 'userTokenRegenerated': {
const user = await this.usersRepository.findOneByOrFail({ id: body.id }) as LocalUser;
const user = await this.usersRepository.findOneByOrFail({ id: body.id }) as MiLocalUser;
this.localUserByNativeTokenCache.delete(body.oldToken);
this.localUserByNativeTokenCache.set(body.newToken, user);
break;
Expand All @@ -197,7 +197,7 @@ export class CacheService implements OnApplicationShutdown {
}

@bindThis
public findUserById(userId: User['id']) {
public findUserById(userId: MiUser['id']) {
return this.userByIdCache.fetch(userId, () => this.usersRepository.findOneByOrFail({ id: userId }));
}

Expand Down
Loading

0 comments on commit f93452c

Please sign in to comment.