fix performance drop in notes/mentions endpoint

This commit is contained in:
Hazelnoot 2025-06-04 10:40:07 -04:00
parent dae544b353
commit 6fe335f843

View file

@ -64,9 +64,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId) ps.sinceId, ps.untilId)
.andWhere(new Brackets(qb => qb .andWhere(new Brackets(qb => qb
.orWhere(':meId = ANY (note.mentions)') .where(':meIdAsList <@ note.mentions')
.orWhere(':meId = ANY (note.visibleUserIds)'))) .orWhere(':meIdAsList <@ note.visibleUserIds')))
.setParameters({ meId: me.id }) .setParameters({ meIdAsList: [me.id] })
// Avoid scanning primary key index // Avoid scanning primary key index
.orderBy('CONCAT(note.id)', 'DESC') .orderBy('CONCAT(note.id)', 'DESC')
.innerJoinAndSelect('note.user', 'user') .innerJoinAndSelect('note.user', 'user')
@ -80,7 +80,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateMutedUserQueryForNotes(query, me); this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateMutedNoteThreadQuery(query, me); this.queryService.generateMutedNoteThreadQuery(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me); this.queryService.generateBlockedUserQueryForNotes(query, me);
this.queryService.generateMutedUserRenotesQueryForNotes(query, me); // A renote can't mention a user, so it will never appear here anyway.
//this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
if (ps.visibility) { if (ps.visibility) {
query.andWhere('note.visibility = :visibility', { visibility: ps.visibility }); query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });