Open FoxTale-Labs opened 2 months ago
A lynt with replies cannot be deleted and it'll error out with "An unknown error occured: 500"
I remember someone talking about this in the discord before I haven't seen it for myself
same issue (ignore the content lmao)
https://github.com/user-attachments/assets/0626510f-6833-47d1-9f1c-30ccd7692de9
The way that deleting posts works is kinda dumb
From src/api/utils.ts
export async function deleteLynt(lyntId: string) {
await db.transaction(async (trx) => {
// Get all comments under this lynt
const comments = await trx.select({ id: lynts.id }).from(lynts).where(eq(lynts.parent, lyntId));
const commentIds = comments.map((comment) => comment.id);
const allIds = [lyntId, ...commentIds];
// Delete likes associated with the comments and the original lynt
await trx.delete(likes).where(inArray(likes.lynt_id, allIds));
// Delete notifications associated with the comments and the original lynt
await trx.delete(notifications).where(inArray(notifications.lyntId, allIds));
// Delete history entries associated with the comments and the original lynt
await trx.delete(history).where(inArray(history.lynt_id, allIds));
// Delete all comments under this lynt
await trx.delete(lynts).where(and(eq(lynts.parent, lyntId), eq(lynts.reposted, false)));
// Update reposts of this lynt
await trx
.update(lynts)
.set({
content: sql`${lynts.content} || '\nThe Lynt this user is reposting has been since deleted.'`,
parent: null
})
.where(and(eq(lynts.parent, lyntId), eq(lynts.reposted, true)));
// Delete the original lynt
await trx.delete(lynts).where(eq(lynts.id, lyntId));
});
}
All this code could have been replaced with a few cascade delete, I'm pretty sure
The way that deleting posts works is kinda dumb
From
src/api/utils.ts
export async function deleteLynt(lyntId: string) { await db.transaction(async (trx) => { // Get all comments under this lynt const comments = await trx.select({ id: lynts.id }).from(lynts).where(eq(lynts.parent, lyntId)); const commentIds = comments.map((comment) => comment.id); const allIds = [lyntId, ...commentIds]; // Delete likes associated with the comments and the original lynt await trx.delete(likes).where(inArray(likes.lynt_id, allIds)); // Delete notifications associated with the comments and the original lynt await trx.delete(notifications).where(inArray(notifications.lyntId, allIds)); // Delete history entries associated with the comments and the original lynt await trx.delete(history).where(inArray(history.lynt_id, allIds)); // Delete all comments under this lynt await trx.delete(lynts).where(and(eq(lynts.parent, lyntId), eq(lynts.reposted, false))); // Update reposts of this lynt await trx .update(lynts) .set({ content: sql`${lynts.content} || '\nThe Lynt this user is reposting has been since deleted.'`, parent: null }) .where(and(eq(lynts.parent, lyntId), eq(lynts.reposted, true))); // Delete the original lynt await trx.delete(lynts).where(eq(lynts.id, lyntId)); }); }
All this code could have been replaced with a few cascade delete, I'm pretty sure
A lot of stuff in the codebase is pretty shit
same issue (ignore the content lmao)
https://github.com/user-attachments/assets/0626510f-6833-47d1-9f1c-30ccd7692de9
I can't play this video for some reason
A lynt with replies cannot be deleted and it'll error out with "An unknown error occured: 500"