From 1773ae14e32eab0bddcdaa8fca33fecf095d99d1 Mon Sep 17 00:00:00 2001 From: Natty Date: Thu, 20 Apr 2023 21:16:36 +0200 Subject: [PATCH] Renote button optimization --- .../backend/src/server/api/endpoints/notes/renotes.ts | 11 +++++++++-- packages/client/src/components/MkRenoteButton.vue | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/notes/renotes.ts b/packages/backend/src/server/api/endpoints/notes/renotes.ts index f313616be2..df801c7fc4 100644 --- a/packages/backend/src/server/api/endpoints/notes/renotes.ts +++ b/packages/backend/src/server/api/endpoints/notes/renotes.ts @@ -38,6 +38,7 @@ export const paramDef = { type: "object", properties: { noteId: { type: "string", format: "misskey:id" }, + userId: { type: "string", format: "misskey:id" }, limit: { type: "integer", minimum: 1, maximum: 100, default: 10 }, sinceId: { type: "string", format: "misskey:id" }, untilId: { type: "string", format: "misskey:id" }, @@ -52,13 +53,19 @@ export default define(meta, paramDef, async (ps, user) => { throw err; }); - const query = makePaginationQuery( + let query = makePaginationQuery( Notes.createQueryBuilder("note"), ps.sinceId, ps.untilId, ) .andWhere("note.renoteId = :renoteId", { renoteId: note.id }) - .innerJoinAndSelect("note.user", "user") + .innerJoinAndSelect("note.user", "user"); + + if (ps.userId) { + query.andWhere("user.id = :userId", { userId: ps.userId }); + } + + query .leftJoinAndSelect("user.avatar", "avatar") .leftJoinAndSelect("user.banner", "banner") .leftJoinAndSelect("note.reply", "reply") diff --git a/packages/client/src/components/MkRenoteButton.vue b/packages/client/src/components/MkRenoteButton.vue index 8815666936..e21611b81b 100644 --- a/packages/client/src/components/MkRenoteButton.vue +++ b/packages/client/src/components/MkRenoteButton.vue @@ -69,11 +69,11 @@ const renote = async (viaKeyboard = false, ev?: MouseEvent) => { const renotes = await os.api("notes/renotes", { noteId: props.note.id, - limit: 11, + userId: $i.id, + limit: 1, }); - const users = renotes.map((x) => x.user.id); - const hasRenotedBefore = users.includes($i.id); + const hasRenotedBefore = renotes.length > 0; let buttonActions: Array = [];