diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-07 18:00:56 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-10-07 18:00:56 +0900 |
| commit | 8c684d539181f030d03db1a6e0f408ae5d8a93ce (patch) | |
| tree | efed56fb1d1a10384e2464abc5dd61e4f3032243 /packages/backend/src/server/api/endpoints/users/notes.ts | |
| parent | refactor (diff) | |
| download | sharkey-8c684d539181f030d03db1a6e0f408ae5d8a93ce.tar.gz sharkey-8c684d539181f030d03db1a6e0f408ae5d8a93ce.tar.bz2 sharkey-8c684d539181f030d03db1a6e0f408ae5d8a93ce.zip | |
enhance(backend): User TLをRedisにキャッシュされる以前まで遡れるように
#11958
Diffstat (limited to 'packages/backend/src/server/api/endpoints/users/notes.ts')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/users/notes.ts | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts index 4c0f0cc588..becc6debbb 100644 --- a/packages/backend/src/server/api/endpoints/users/notes.ts +++ b/packages/backend/src/server/api/endpoints/users/notes.ts @@ -10,10 +10,10 @@ import type { MiNote, NotesRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { DI } from '@/di-symbols.js'; -import { GetterService } from '@/server/api/GetterService.js'; import { CacheService } from '@/core/CacheService.js'; import { IdService } from '@/core/IdService.js'; import { isUserRelated } from '@/misc/is-user-related.js'; +import { QueryService } from '@/core/QueryService.js'; import { ApiError } from '../../error.js'; export const meta = { @@ -67,7 +67,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- private notesRepository: NotesRepository, private noteEntityService: NoteEntityService, - private getterService: GetterService, + private queryService: QueryService, private cacheService: CacheService, private idService: IdService, ) { @@ -148,6 +148,43 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- timeline.sort((a, b) => a.id > b.id ? -1 : 1); + // fallback to database + if (timeline.length === 0) { + //#region Construct query + const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) + .andWhere('note.userId = :userId', { userId: ps.userId }) + .innerJoinAndSelect('note.user', 'user') + .leftJoinAndSelect('note.reply', 'reply') + .leftJoinAndSelect('note.renote', 'renote') + .leftJoinAndSelect('note.channel', 'channel') + .leftJoinAndSelect('reply.user', 'replyUser') + .leftJoinAndSelect('renote.user', 'renoteUser'); + + query.andWhere(new Brackets(qb => { + qb.orWhere('note.channelId IS NULL'); + qb.orWhere('channel.isSensitive = false'); + })); + + this.queryService.generateVisibilityQuery(query, me); + + if (ps.withFiles) { + query.andWhere('note.fileIds != \'{}\''); + } + + if (ps.includeMyRenotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :userId', { userId: ps.userId }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } + //#endregion + + timeline = await query.limit(ps.limit).getMany(); + } + return await this.noteEntityService.packMany(timeline, me); }); } |