denormalize more columns

This commit is contained in:
Namekuji 2023-07-26 21:58:38 -04:00
parent a7fdf68bd2
commit b37717d431
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
4 changed files with 25 additions and 35 deletions

View file

@ -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<text, int>,
"renoteUserId" ascii,
"renoteUserHost" text,
"reactions" map<text, int>, -- Reactions
"noteEdit" set<frozen<note_edit_history>>, -- Edit History
"updatedAt" timestamp,
PRIMARY KEY ("createdAtDate", "createdAt", "id")

View file

@ -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,
};
}

View file

@ -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) {

View file

@ -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,