mirror of
https://github.com/paricafe/misskey.git
synced 2025-02-17 13:37:29 -06:00
fix: Try using CacheService
to avoid excess db lookups
This isn't perfect, theoretically if some massive number of users blocked the user making this request the set lookup could take a long amount of time, but eh, it works, and that scenario is highly unlikely.
This commit is contained in:
parent
af52d3198b
commit
0595947fc0
1 changed files with 17 additions and 1 deletions
|
@ -17,6 +17,7 @@ import { DebounceLoader } from '@/misc/loader.js';
|
||||||
import { IdService } from '@/core/IdService.js';
|
import { IdService } from '@/core/IdService.js';
|
||||||
import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js';
|
import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js';
|
||||||
import type { OnModuleInit } from '@nestjs/common';
|
import type { OnModuleInit } from '@nestjs/common';
|
||||||
|
import type { CacheService } from '../CacheService.js';
|
||||||
import type { CustomEmojiService } from '../CustomEmojiService.js';
|
import type { CustomEmojiService } from '../CustomEmojiService.js';
|
||||||
import type { ReactionService } from '../ReactionService.js';
|
import type { ReactionService } from '../ReactionService.js';
|
||||||
import type { UserEntityService } from './UserEntityService.js';
|
import type { UserEntityService } from './UserEntityService.js';
|
||||||
|
@ -50,6 +51,7 @@ function getAppearNoteIds(notes: MiNote[]): Set<string> {
|
||||||
export class NoteEntityService implements OnModuleInit {
|
export class NoteEntityService implements OnModuleInit {
|
||||||
private userEntityService: UserEntityService;
|
private userEntityService: UserEntityService;
|
||||||
private driveFileEntityService: DriveFileEntityService;
|
private driveFileEntityService: DriveFileEntityService;
|
||||||
|
private cacheService: CacheService;
|
||||||
private customEmojiService: CustomEmojiService;
|
private customEmojiService: CustomEmojiService;
|
||||||
private reactionService: ReactionService;
|
private reactionService: ReactionService;
|
||||||
private reactionsBufferingService: ReactionsBufferingService;
|
private reactionsBufferingService: ReactionsBufferingService;
|
||||||
|
@ -95,6 +97,7 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.userEntityService = this.moduleRef.get('UserEntityService');
|
this.userEntityService = this.moduleRef.get('UserEntityService');
|
||||||
this.driveFileEntityService = this.moduleRef.get('DriveFileEntityService');
|
this.driveFileEntityService = this.moduleRef.get('DriveFileEntityService');
|
||||||
|
this.cacheService = this.moduleRef.get('CacheService');
|
||||||
this.customEmojiService = this.moduleRef.get('CustomEmojiService');
|
this.customEmojiService = this.moduleRef.get('CustomEmojiService');
|
||||||
this.reactionService = this.moduleRef.get('ReactionService');
|
this.reactionService = this.moduleRef.get('ReactionService');
|
||||||
this.reactionsBufferingService = this.moduleRef.get('ReactionsBufferingService');
|
this.reactionsBufferingService = this.moduleRef.get('ReactionsBufferingService');
|
||||||
|
@ -179,6 +182,12 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hide && meId && packedNote.userId !== meId) {
|
||||||
|
const isBlocked = (await this.cacheService.userBlockedCache.fetch(meId)).has(packedNote.userId);
|
||||||
|
|
||||||
|
if (isBlocked) hide = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (hide) {
|
if (hide) {
|
||||||
packedNote.visibleUserIds = undefined;
|
packedNote.visibleUserIds = undefined;
|
||||||
packedNote.fileIds = [];
|
packedNote.fileIds = [];
|
||||||
|
@ -300,7 +309,8 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// フォロワーかどうか
|
// フォロワーかどうか
|
||||||
const [following, user] = await Promise.all([
|
const [blocked, following, user] = await Promise.all([
|
||||||
|
this.cacheService.userBlockingCache.fetch(meId).then((ids) => ids.has(note.userId)),
|
||||||
this.followingsRepository.count({
|
this.followingsRepository.count({
|
||||||
where: {
|
where: {
|
||||||
followeeId: note.userId,
|
followeeId: note.userId,
|
||||||
|
@ -322,6 +332,12 @@ export class NoteEntityService implements OnModuleInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meId != null) {
|
||||||
|
const isBlocked = (await this.cacheService.userBlockedCache.fetch(meId)).has(note.userId);
|
||||||
|
|
||||||
|
if (isBlocked) return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue