Renote button optimization

This commit is contained in:
Natty 2023-04-20 21:16:36 +02:00
parent 12f0bd4e2d
commit e4b8b35e82
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
2 changed files with 12 additions and 5 deletions

View File

@ -38,6 +38,7 @@ export const paramDef = {
type: "object", type: "object",
properties: { properties: {
noteId: { type: "string", format: "misskey:id" }, noteId: { type: "string", format: "misskey:id" },
userId: { type: "string", format: "misskey:id" },
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 }, limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
sinceId: { type: "string", format: "misskey:id" }, sinceId: { type: "string", format: "misskey:id" },
untilId: { 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; throw err;
}); });
const query = makePaginationQuery( let query = makePaginationQuery(
Notes.createQueryBuilder("note"), Notes.createQueryBuilder("note"),
ps.sinceId, ps.sinceId,
ps.untilId, ps.untilId,
) )
.andWhere("note.renoteId = :renoteId", { renoteId: note.id }) .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.avatar", "avatar")
.leftJoinAndSelect("user.banner", "banner") .leftJoinAndSelect("user.banner", "banner")
.leftJoinAndSelect("note.reply", "reply") .leftJoinAndSelect("note.reply", "reply")

View File

@ -58,11 +58,11 @@ const renote = async (viaKeyboard = false, ev?: MouseEvent) => {
const renotes = await os.api('notes/renotes', { const renotes = await os.api('notes/renotes', {
noteId: props.note.id, noteId: props.note.id,
limit: 11, userId: $i.id,
limit: 1,
}); });
const users = renotes.map(x => x.user.id); const hasRenotedBefore = renotes.length > 0;
const hasRenotedBefore = users.includes($i.id);
let buttonActions = [{ let buttonActions = [{
text: i18n.ts.renote, text: i18n.ts.renote,