mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	perf(backend): improve my reaction population performance
This commit is contained in:
		
							parent
							
								
									2dfbf97db4
								
							
						
					
					
						commit
						4d1d25e02f
					
				
					 1 changed files with 4 additions and 5 deletions
				
			
		| 
						 | 
					@ -177,10 +177,9 @@ export class NoteEntityService implements OnModuleInit {
 | 
				
			||||||
			const reaction = _hint_.myReactions.get(noteId);
 | 
								const reaction = _hint_.myReactions.get(noteId);
 | 
				
			||||||
			if (reaction) {
 | 
								if (reaction) {
 | 
				
			||||||
				return this.reactionService.convertLegacyReaction(reaction.reaction);
 | 
									return this.reactionService.convertLegacyReaction(reaction.reaction);
 | 
				
			||||||
			} else if (reaction === null) {
 | 
								} else {
 | 
				
			||||||
				return undefined;
 | 
									return undefined;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		// 実装上抜けがあるだけかもしれないので、「ヒントに含まれてなかったら(=undefinedなら)return」のようにはしない
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
 | 
							// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
 | 
				
			||||||
| 
						 | 
					@ -387,11 +386,11 @@ export class NoteEntityService implements OnModuleInit {
 | 
				
			||||||
			const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);
 | 
								const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);
 | 
				
			||||||
			// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
 | 
								// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
 | 
				
			||||||
			const oldId = this.idService.gen(Date.now() - 2000);
 | 
								const oldId = this.idService.gen(Date.now() - 2000);
 | 
				
			||||||
			const targets = [...notes.filter(n => n.id < oldId).map(n => n.id), ...renoteIds];
 | 
								const targets = [...notes.filter(n => (n.id < oldId) && (Object.keys(n.reactions).length > 0)).map(n => n.id), ...renoteIds];
 | 
				
			||||||
			const myReactions = await this.noteReactionsRepository.findBy({
 | 
								const myReactions = targets.length > 0 ? await this.noteReactionsRepository.findBy({
 | 
				
			||||||
				userId: meId,
 | 
									userId: meId,
 | 
				
			||||||
				noteId: In(targets),
 | 
									noteId: In(targets),
 | 
				
			||||||
			});
 | 
								}) : [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (const target of targets) {
 | 
								for (const target of targets) {
 | 
				
			||||||
				myReactionsMap.set(target, myReactions.find(reaction => reaction.noteId === target) ?? null);
 | 
									myReactionsMap.set(target, myReactions.find(reaction => reaction.noteId === target) ?? null);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue