fix: clear home timeline of deleted user
This commit is contained in:
parent
91762bb8ca
commit
ef97630460
3 changed files with 29 additions and 3 deletions
|
@ -216,6 +216,8 @@ CREATE TABLE home_timeline (
|
||||||
|
|
||||||
CREATE INDEX home_by_id ON home_timeline ("id");
|
CREATE INDEX home_by_id ON home_timeline ("id");
|
||||||
|
|
||||||
|
CREATE INDEX home_by_feed_user_id ON home_timeline ("feedUserId");
|
||||||
|
|
||||||
CREATE TABLE reaction (
|
CREATE TABLE reaction (
|
||||||
"id" text,
|
"id" text,
|
||||||
"noteId" ascii,
|
"noteId" ascii,
|
||||||
|
|
|
@ -116,6 +116,7 @@ export const scyllaQueries = {
|
||||||
select: {
|
select: {
|
||||||
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" = ?`,
|
||||||
|
byUser: `SELECT * FROM home_timeline WHERE "feedUserId" = ?`,
|
||||||
},
|
},
|
||||||
delete: `DELETE FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ?`,
|
delete: `DELETE FROM home_timeline WHERE "feedUserId" = ? AND "createdAtDate" = ? AND "createdAt" = ? AND "userId" = ?`,
|
||||||
update: {
|
update: {
|
||||||
|
|
|
@ -46,12 +46,33 @@ export async function deleteAccount(
|
||||||
let cursor: Note["id"] | null = null;
|
let cursor: Note["id"] | null = null;
|
||||||
|
|
||||||
if (scyllaClient) {
|
if (scyllaClient) {
|
||||||
|
// FIXME: Cascading notes won't be deleted. Reply and renote counts will be incorrect.
|
||||||
|
const client = scyllaClient as Client;
|
||||||
|
// Clear user's home timeline
|
||||||
|
scyllaClient.eachRow(
|
||||||
|
prepared.homeTimeline.select.byUser,
|
||||||
|
[user.id],
|
||||||
|
{ prepare: true },
|
||||||
|
(_, row) => {
|
||||||
|
const timeline = parseHomeTimeline(row);
|
||||||
|
client.execute(
|
||||||
|
prepared.homeTimeline.delete,
|
||||||
|
[
|
||||||
|
timeline.feedUserId,
|
||||||
|
timeline.createdAtDate,
|
||||||
|
timeline.createdAt,
|
||||||
|
timeline.userId,
|
||||||
|
],
|
||||||
|
{ prepare: true },
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
// Delete notes
|
||||||
scyllaClient.eachRow(
|
scyllaClient.eachRow(
|
||||||
prepared.note.select.byUserId,
|
prepared.note.select.byUserId,
|
||||||
[user.id],
|
[user.id],
|
||||||
{ prepare: true },
|
{ prepare: true },
|
||||||
(_, row) => {
|
(_, row) => {
|
||||||
const client = scyllaClient as Client;
|
|
||||||
const note = parseScyllaNote(row);
|
const note = parseScyllaNote(row);
|
||||||
const noteDeleteParams = [
|
const noteDeleteParams = [
|
||||||
note.createdAt,
|
note.createdAt,
|
||||||
|
@ -60,9 +81,11 @@ export async function deleteAccount(
|
||||||
note.userHost ?? "local",
|
note.userHost ?? "local",
|
||||||
note.visibility,
|
note.visibility,
|
||||||
] as [Date, Date, string, string, string];
|
] as [Date, Date, string, string, string];
|
||||||
|
// Delete note from global feed
|
||||||
client.execute(prepared.note.delete, noteDeleteParams, {
|
client.execute(prepared.note.delete, noteDeleteParams, {
|
||||||
prepare: true,
|
prepare: true,
|
||||||
});
|
});
|
||||||
|
// Delete note from home timelines
|
||||||
client.eachRow(
|
client.eachRow(
|
||||||
prepared.homeTimeline.select.byId,
|
prepared.homeTimeline.select.byId,
|
||||||
[note.id],
|
[note.id],
|
||||||
|
@ -140,7 +163,7 @@ export async function deleteAccount(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.succ("All of notes deleted");
|
logger.succ("All associated notes deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -170,7 +193,7 @@ export async function deleteAccount(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.succ("All of files deleted");
|
logger.succ("All associated files deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue