From eac2ff4a47feaa6f04c9c7211b2b967962597522 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Thu, 28 Sep 2023 11:59:54 -0400 Subject: [PATCH] perf: construct scyllaNote instead of querying --- packages/backend/src/services/note/create.ts | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index fb989f33ee..87329439d0 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -75,10 +75,10 @@ import { redisClient } from "@/db/redis.js"; import { Mutex } from "redis-semaphore"; import { parseHomeTimeline, - parseScyllaNote, prepared, scyllaClient, - ScyllaPoll, + type ScyllaNote, + type ScyllaPoll, } from "@/db/scylla.js"; import { userByIdCache, userDenormalizedCache } from "../user-cache.js"; import { langmap } from "@/misc/langmap.js"; @@ -843,6 +843,7 @@ async function insertNote( width: file.properties.width ?? null, height: file.properties.height ?? null, }); + const files = data.files?.map(fileMapper); const replyText = data.reply?.text ?? null; const replyCw = data.reply?.cw ?? null; // TODO: move drive files to scylla or cache in redis/dragonfly @@ -905,7 +906,7 @@ async function insertNote( insert.uri, insert.url, insert.score ?? 0, - data.files?.map(fileMapper), + files, insert.visibleUserIds, insert.mentions, insert.mentionedRemoteUsers, @@ -957,6 +958,22 @@ async function insertNote( }, ); } + + const scyllaNote: ScyllaNote = { + ...insert, + createdAtDate: insert.createdAt, + files: files ?? [], + poll, + replyText, + replyCw, + replyFiles: replyFiles ?? [], + renoteText, + renoteCw, + renoteFiles: renoteFiles ?? [], + noteEdit: [], + }; + + return scyllaNote; } else { if (insert.hasPoll) { // Start transaction @@ -990,17 +1007,6 @@ async function insertNote( } } - if (scyllaClient) { - const result = await scyllaClient.execute( - prepared.note.select.byId, - [insert.id], - { prepare: true }, - ); - if (result.rowLength > 0) { - return parseScyllaNote(result.first()); - } - } - return insert; } catch (e) { // duplicate key error