fix: proper cql
This commit is contained in:
parent
4f5f601c1d
commit
2d1a6d8ab0
2 changed files with 44 additions and 31 deletions
|
@ -49,9 +49,9 @@ export const scyllaQueries = {
|
||||||
byIds: `SELECT * FROM note_by_id WHERE "id" IN ?`,
|
byIds: `SELECT * FROM note_by_id WHERE "id" IN ?`,
|
||||||
byUserId: `SELECT * FROM note_by_user_id WHERE "userId" = ?`,
|
byUserId: `SELECT * FROM note_by_user_id WHERE "userId" = ?`,
|
||||||
byRenoteId: `SELECT * FROM note_by_renote_id WHERE "renoteId" = ?`,
|
byRenoteId: `SELECT * FROM note_by_renote_id WHERE "renoteId" = ?`,
|
||||||
byReplyId: `SELECT * FROM note WHERE "replyId" = ?`
|
byReplyId: `SELECT * FROM note WHERE "replyId" = ?`,
|
||||||
},
|
},
|
||||||
delete: `DELETE FROM note WHERE ("createdAtDate", "createdAt", "userId", "userHost", "visibility") IN ?`,
|
delete: `DELETE FROM note WHERE "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? AND "userHost" = ? AND "visibility" = ?`,
|
||||||
update: {
|
update: {
|
||||||
renoteCount: `UPDATE note SET
|
renoteCount: `UPDATE note SET
|
||||||
"renoteCount" = ?,
|
"renoteCount" = ?,
|
||||||
|
@ -114,7 +114,7 @@ export const scyllaQueries = {
|
||||||
byUserAndDate: `SELECT * FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ?`,
|
byUserAndDate: `SELECT * FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ?`,
|
||||||
byId: `SELECT * FROM home_timeline WHERE "id" = ?`,
|
byId: `SELECT * FROM home_timeline WHERE "id" = ?`,
|
||||||
},
|
},
|
||||||
delete: `DELETE FROM home_timeline WHERE ("feedUserId", "createdAtDate", "createdAt", "userId") IN ?`,
|
delete: `DELETE FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ?`,
|
||||||
update: {
|
update: {
|
||||||
renoteCount: `UPDATE home_timeline SET
|
renoteCount: `UPDATE home_timeline SET
|
||||||
"renoteCount" = ?,
|
"renoteCount" = ?,
|
||||||
|
@ -128,7 +128,7 @@ export const scyllaQueries = {
|
||||||
"reactions" = ?,
|
"reactions" = ?,
|
||||||
"score" = ?
|
"score" = ?
|
||||||
WHERE "feedUserId" = ? AND "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? IF EXISTS`,
|
WHERE "feedUserId" = ? AND "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ? IF EXISTS`,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
localTimeline: {
|
localTimeline: {
|
||||||
select: {
|
select: {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Brackets, In } from "typeorm";
|
import { Brackets, In, IsNull } from "typeorm";
|
||||||
import { publishNoteStream } from "@/services/stream.js";
|
import { publishNoteStream } from "@/services/stream.js";
|
||||||
import renderDelete from "@/remote/activitypub/renderer/delete.js";
|
import renderDelete from "@/remote/activitypub/renderer/delete.js";
|
||||||
import renderAnnounce from "@/remote/activitypub/renderer/announce.js";
|
import renderAnnounce from "@/remote/activitypub/renderer/announce.js";
|
||||||
|
@ -227,33 +227,46 @@ export default async function (
|
||||||
if (scyllaClient) {
|
if (scyllaClient) {
|
||||||
const notesToDelete = [note, ...cascadingNotes];
|
const notesToDelete = [note, ...cascadingNotes];
|
||||||
|
|
||||||
const noteDeleteParams = notesToDelete.map((n) => {
|
// Delete from note table
|
||||||
const date = new Date(n.createdAt.getTime());
|
const noteDeleteParams = notesToDelete.map(
|
||||||
return [date, date, n.userId, n.userHost ?? "local", n.visibility];
|
(n) =>
|
||||||
});
|
[
|
||||||
await scyllaClient.execute(prepared.note.delete, noteDeleteParams, {
|
n.createdAt,
|
||||||
prepare: true,
|
n.createdAt,
|
||||||
});
|
n.userId,
|
||||||
|
n.userHost ?? "local",
|
||||||
const noteUserIds = new Set(notesToDelete.map((n) => n.userId));
|
n.visibility,
|
||||||
const meAndFollowers: string[] = [note.userId];
|
] as [Date, Date, string, string, string],
|
||||||
for (const id of noteUserIds) {
|
);
|
||||||
const list = await LocalFollowersCache.init(id).then((cache) =>
|
for (const param of noteDeleteParams) {
|
||||||
cache.getAll(),
|
scyllaClient.execute(prepared.note.delete, param, {
|
||||||
);
|
prepare: true,
|
||||||
meAndFollowers.push(...list);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete from home timelines
|
||||||
|
const localUserIds = await Users.find({
|
||||||
|
select: ["id"],
|
||||||
|
where: {
|
||||||
|
host: IsNull(),
|
||||||
|
},
|
||||||
|
}).then((users) => users.map(({ id }) => id)); // TODO: cache?
|
||||||
|
const homeDeleteParams = localUserIds.flatMap((feedUserId) =>
|
||||||
|
notesToDelete.map(
|
||||||
|
(n) =>
|
||||||
|
[feedUserId, n.createdAt, n.createdAt, n.userId] as [
|
||||||
|
string,
|
||||||
|
Date,
|
||||||
|
Date,
|
||||||
|
string,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
for (const param of homeDeleteParams) {
|
||||||
|
scyllaClient.execute(prepared.homeTimeline.delete, param, {
|
||||||
|
prepare: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const feedUserIds = new Set(meAndFollowers);
|
|
||||||
const homeDeleteParams = notesToDelete.map((n) => {
|
|
||||||
const tuples: [string, Date, Date, string][] = [];
|
|
||||||
for (const feedUserId of feedUserIds) {
|
|
||||||
tuples.push([feedUserId, n.createdAt, n.createdAt, n.userId]);
|
|
||||||
}
|
|
||||||
return tuples;
|
|
||||||
});
|
|
||||||
await scyllaClient.execute(prepared.homeTimeline.delete, homeDeleteParams, {
|
|
||||||
prepare: true,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
await Notes.delete({
|
await Notes.delete({
|
||||||
id: note.id,
|
id: note.id,
|
||||||
|
|
Loading…
Reference in a new issue