From b37717d431688a0f66dba582bc124a6cc00993ad Mon Sep 17 00:00:00 2001 From: Namekuji Date: Wed, 26 Jul 2023 21:58:38 -0400 Subject: [PATCH] denormalize more columns --- .../cql/1689400417034_timeline/up.cql | 7 ++- packages/backend/src/db/scylla.ts | 43 +++++-------------- .../backend/src/server/api/common/getters.ts | 3 +- packages/backend/src/services/note/create.ts | 7 ++- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql b/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql index 55591ae75f..10137086d3 100644 --- a/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql +++ b/packages/backend/native-utils/scylla-migration/cql/1689400417034_timeline/up.cql @@ -51,9 +51,14 @@ CREATE TABLE IF NOT EXISTS note ( -- Models timeline "channelId" ascii, -- Channel "channelName" text, "userId" ascii, -- User + "userHost" text, "replyId" ascii, -- Reply + "replyUserId" ascii, + "replyUserHost" text, "renoteId" ascii, -- Boost - "reactions" map, + "renoteUserId" ascii, + "renoteUserHost" text, + "reactions" map, -- Reactions "noteEdit" set>, -- Edit History "updatedAt" timestamp, PRIMARY KEY ("createdAtDate", "createdAt", "id") diff --git a/packages/backend/src/db/scylla.ts b/packages/backend/src/db/scylla.ts index af1ae67649..dbd1cd2d2d 100644 --- a/packages/backend/src/db/scylla.ts +++ b/packages/backend/src/db/scylla.ts @@ -45,14 +45,19 @@ export const prepared = { "channelId", "channelName", "userId", + "userHost", "replyId", + "replyUserId", + "replyUserHost", "renoteId", + "renoteUserId", + "renoteUserHost", "reactions", "noteEdit", "updatedAt" ) VALUES - (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, select: { byDate: `SELECT * FROM note WHERE "createdAtDate" IN ?`, byId: `SELECT * FROM note WHERE "id" IN ?`, @@ -111,35 +116,9 @@ export interface ScyllaNoteEditHistory { export type ScyllaNote = Note & { createdAtDate: Date; - createdAt: Note["createdAt"]; - id: Note["id"]; - visibility: Note["visibility"]; - text: Note["text"]; - name: Note["name"]; - cw: Note["cw"]; - localOnly: Note["localOnly"]; - renoteCount: Note["renoteCount"]; - repliesCount: Note["repliesCount"]; - uri: Note["uri"]; - url: Note["url"]; - score: Note["score"]; files: ScyllaDriveFile[]; - fileIds: Note["fileIds"]; - attachedFileTypes: Note["attachedFileTypes"]; - visibleUserIds: Note["visibleUserIds"]; - mentions: Note["mentions"]; - emojis: Note["emojis"]; - tags: Note["tags"]; - hasPoll: Note["hasPoll"]; - threadId: Note["threadId"]; - channelId: Note["channelId"]; channelName: string; - userId: Note["userId"]; - replyId: Note["replyId"]; - renoteId: Note["renoteId"]; - reactions: Note["reactions"]; noteEdit: ScyllaNoteEditHistory[]; - updatedAt: Note["updatedAt"]; }; export function parseScyllaNote(row: types.Row): ScyllaNote { @@ -170,8 +149,13 @@ export function parseScyllaNote(row: types.Row): ScyllaNote { channelId: row.get("channelId"), channelName: row.get("channelName"), userId: row.get("userId"), + userHost: row.get("userHost"), replyId: row.get("replyId"), + replyUserId: row.get("replyUserId"), + replyUserHost: row.get("replyUserHost"), renoteId: row.get("replyId"), + renoteUserId: row.get("renoteUserId"), + renoteUserHost: row.get("renoteUserHost"), reactions: row.get("reactions"), noteEdit: row.get("noteEdit"), updatedAt: row.get("updatedAt"), @@ -179,13 +163,8 @@ export function parseScyllaNote(row: types.Row): ScyllaNote { channel: null, renote: null, reply: null, - renoteUserHost: null, - renoteUserId: null, mentionedRemoteUsers: "", - replyUserHost: null, - replyUserId: null, user: null, - userHost: null, }; } diff --git a/packages/backend/src/server/api/common/getters.ts b/packages/backend/src/server/api/common/getters.ts index 6f7e0c7036..4c642ddd21 100644 --- a/packages/backend/src/server/api/common/getters.ts +++ b/packages/backend/src/server/api/common/getters.ts @@ -36,7 +36,8 @@ export async function getNote( candidate.visibleUserIds.includes(me.id) || // visible to me candidate.mentions.includes(me.id) || // mentioned me (candidate.visibility === "followers" && - (await cache.isFollowing(candidate.userId))); + (await cache.isFollowing(candidate.userId))) || // following + candidate.replyUserId === me.id; // replied to myself } if (valid) { diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 46386e4ed1..78d98ac7c7 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -796,9 +796,14 @@ async function insertNote( insert.threadId, data.channel?.id, data.channel?.name, - user.id, + insert.userId, + insert.userHost, insert.replyId, + insert.replyUserId, + insert.replyUserHost, insert.renoteId, + insert.renoteUserId, + insert.renoteUserHost, null, null, null,