fix update query

This commit is contained in:
Namekuji 2023-08-12 03:31:35 -04:00
parent 3b50978f48
commit 3e4961445f
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
4 changed files with 31 additions and 8 deletions

View file

@ -54,15 +54,15 @@ export const scyllaQueries = {
renoteCount: `UPDATE note SET renoteCount: `UPDATE note SET
"renoteCount" = ?, "renoteCount" = ?,
"score" = ? "score" = ?
WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? IF EXISTS`, WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? AND "userHost" = ? AND "visibility" = ? IF EXISTS`,
repliesCount: `UPDATE note SET repliesCount: `UPDATE note SET
"repliesCount" = ? "repliesCount" = ?
WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? IF EXISTS`, WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? AND "userHost" = ? AND "visibility" = ? IF EXISTS`,
reactions: `UPDATE note SET reactions: `UPDATE note SET
"emojis" = ?, "emojis" = ?,
"reactions" = ?, "reactions" = ?,
"score" = ? "score" = ?
WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? IF EXISTS`, WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? AND "userHost" = ? AND "visibility" = ? IF EXISTS`,
}, },
}, },
homeTimeline: { homeTimeline: {

View file

@ -685,7 +685,15 @@ async function incRenoteCount(renote: Note) {
const score = isNaN(renote.score) ? 0 : renote.score; const score = isNaN(renote.score) ? 0 : renote.score;
await scyllaClient.execute( await scyllaClient.execute(
prepared.note.update.renoteCount, prepared.note.update.renoteCount,
[count + 1, score + 1, renote.createdAt, renote.createdAt, renote.userId], [
count + 1,
score + 1,
renote.createdAt,
renote.createdAt,
renote.userId,
renote.userHost ?? "local",
renote.visibility,
],
{ prepare: true }, { prepare: true },
); );
} else { } else {
@ -852,9 +860,13 @@ async function insertNote(
// Do not issue BATCH because different queries of inserting post to home timelines involve different partitions // Do not issue BATCH because different queries of inserting post to home timelines involve different partitions
for (const follower of localFollowers) { for (const follower of localFollowers) {
// no need to wait // no need to wait
scyllaClient.execute(prepared.homeTimeline.insert, [follower, ...params], { scyllaClient.execute(
prepared.homeTimeline.insert,
[follower, ...params],
{
prepare: true, prepare: true,
}); },
);
} }
} }
if (insert.hasPoll) { if (insert.hasPoll) {
@ -1025,7 +1037,14 @@ async function saveReply(reply: Note) {
const count = isNaN(reply.repliesCount) ? 0 : reply.repliesCount; const count = isNaN(reply.repliesCount) ? 0 : reply.repliesCount;
await scyllaClient.execute( await scyllaClient.execute(
prepared.note.update.repliesCount, prepared.note.update.repliesCount,
[count + 1, reply.createdAt, reply.createdAt, reply.userId], [
count + 1,
reply.createdAt,
reply.createdAt,
reply.userId,
reply.userHost ?? "local",
reply.visibility,
],
{ prepare: true }, { prepare: true },
); );
} else { } else {

View file

@ -117,6 +117,8 @@ export default async (
date, date,
date, date,
note.userId, note.userId,
note.userHost ?? "local",
note.visibility,
], ],
{ prepare: true }, { prepare: true },
); );

View file

@ -68,6 +68,8 @@ export default async (
date, date,
date, date,
note.userId, note.userId,
note.userHost ?? "local",
note.visibility,
], ],
{ prepare: true }, { prepare: true },
); );