fix: query return value

This commit is contained in:
Namekuji 2023-08-01 03:55:47 -04:00
parent b8e3de7ddf
commit ec05aed492
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
3 changed files with 27 additions and 13 deletions

View file

@ -21,7 +21,7 @@ export async function getNote(
if (scyllaClient) {
const result = await scyllaClient.execute(
prepared.note.select.byId,
[noteId],
[[noteId]],
{ prepare: true },
);
if (result.rowLength > 0) {

View file

@ -85,7 +85,7 @@ export default define(meta, paramDef, async (ps, user) => {
query.push(`AND "id" < ?`);
params.push(ps.untilId);
}
query.push("LIMIT 50"); // Hardcoded to enable prepared query for performance
query.push("LIMIT 50"); // Hardcoded for prepared query
const result = await scyllaClient.execute(query.join(" "), params, {
prepare: true,

View file

@ -67,7 +67,7 @@ import { shouldSilenceInstance } from "@/misc/should-block-instance.js";
import meilisearch from "../../db/meilisearch.js";
import { redisClient } from "@/db/redis.js";
import { Mutex } from "redis-semaphore";
import { prepared, scyllaClient } from "@/db/scylla.js";
import { parseScyllaNote, prepared, scyllaClient } from "@/db/scylla.js";
import { populateEmojis } from "@/misc/populate-emojis.js";
const mutedWordsCache = new Cache<
@ -416,7 +416,7 @@ export default async (
!user.isBot &&
(await countSameRenotes(user.id, data.renote.id, note.id)) === 0
) {
incRenoteCount(data.renote);
await incRenoteCount(data.renote);
}
if (data.poll?.expiresAt) {
@ -676,16 +676,19 @@ async function renderNoteOrRenoteActivity(data: Option, note: Note) {
return renderActivity(content);
}
function incRenoteCount(renote: Note) {
async function incRenoteCount(renote: Note) {
if (scyllaClient) {
const date = new Date(renote.createdAt.getTime());
scyllaClient.execute(prepared.note.update.renoteCount, [
renote.renoteCount + 1,
renote.score + 1,
date,
date,
renote.id,
]);
await scyllaClient.execute(
prepared.note.update.renoteCount,
[
renote.renoteCount + 1,
renote.score + 1,
renote.createdAt,
renote.createdAt,
renote.id,
],
{ prepare: true },
);
} else {
Notes.createQueryBuilder()
.update()
@ -849,6 +852,17 @@ async function insertNote(
await Notes.insert(insert);
}
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