From 6179b2e5f0e39129c188e55cdfac4fcfcdb0752a Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 27 Mar 2023 20:46:26 +0200 Subject: [PATCH] server: add pagination to file attachment timeline As a side effect this also makes the notes appear in chronological order. Changelog: Changed --- .../api/endpoints/drive/files/attached-notes.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts b/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts index 4c4fb1ad0..2958eda65 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts @@ -1,6 +1,7 @@ import { DriveFiles, Notes } from '@/models/index.js'; import define from '@/server/api/define.js'; import { ApiError } from '@/server/api/error.js'; +import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js'; export const meta = { tags: ['drive', 'notes'], @@ -28,6 +29,9 @@ export const paramDef = { type: 'object', properties: { fileId: { type: 'string', format: 'misskey:id' }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, }, required: ['fileId'], } as const; @@ -42,8 +46,13 @@ export default define(meta, paramDef, async (ps, user) => { if (file == null) throw new ApiError('NO_SUCH_FILE'); - const notes = await Notes.createQueryBuilder('note') - .where(':file = ANY(note.fileIds)', { file: file.id }) + const notes = await makePaginationQuery( + Notes.createQueryBuilder('note'), + ps.sinceId, + ps.untilId, + ) + .andWhere(':file = ANY(note.fileIds)', { file: file.id }) + .take(ps.limit) .getMany(); return await Notes.packMany(notes, user, {