mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-21 19:53:50 +01:00
Purge deleted users from user lookup caches
This commit is contained in:
parent
9e5f96b9ad
commit
c6dee2da09
@ -8,6 +8,7 @@ import { MoreThan } from "typeorm";
|
||||
import { deleteFileSync } from "@/services/drive/delete-file.js";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import meilisearch from "@/db/meilisearch.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
|
||||
const logger = queueLogger.createSubLogger("delete-account");
|
||||
|
||||
@ -18,6 +19,7 @@ export async function deleteAccount(
|
||||
|
||||
const user = await Users.findOneBy({ id: job.data.user.id });
|
||||
if (!user) return;
|
||||
const isLocal = Users.isLocalUser(user);
|
||||
|
||||
{
|
||||
// Delete notes
|
||||
@ -98,6 +100,7 @@ export async function deleteAccount(
|
||||
// nop
|
||||
} else {
|
||||
await Users.delete(job.data.user.id);
|
||||
publishInternalEvent(isLocal ? "localUserDeleted" : "remoteUserDeleted", { id: user.id });
|
||||
}
|
||||
|
||||
return "Account deleted";
|
||||
|
@ -38,9 +38,15 @@ export interface InternalStreamTypes {
|
||||
localUserUpdated: {
|
||||
id: User["id"];
|
||||
};
|
||||
localUserDeleted: {
|
||||
id: User["id"];
|
||||
};
|
||||
remoteUserUpdated: {
|
||||
id: User["id"];
|
||||
};
|
||||
remoteUserDeleted: {
|
||||
id: User["id"];
|
||||
};
|
||||
webhookCreated: Webhook;
|
||||
webhookDeleted: Webhook;
|
||||
webhookUpdated: Webhook;
|
||||
|
@ -27,6 +27,19 @@ subscriber.on("message", async (_, data) => {
|
||||
if (obj.channel === "internal") {
|
||||
const { type, body } = obj.message;
|
||||
switch (type) {
|
||||
case "localUserDeleted": {
|
||||
await userByIdCache.delete(body.id);
|
||||
await localUserByIdCache.delete(body.id);
|
||||
const toDelete = Array.from(await localUserByNativeTokenCache.getAll())
|
||||
.filter((v) => v[1]?.id === body.id)
|
||||
.map((v) => v[0]);
|
||||
await localUserByNativeTokenCache.delete(...toDelete);
|
||||
const uriCacheToDelete = Array.from(await uriPersonCache.getAll())
|
||||
.filter((v) => v[1]?.id === body.id)
|
||||
.map((v) => v[0]);
|
||||
await uriPersonCache.delete(...uriCacheToDelete);
|
||||
break;
|
||||
}
|
||||
case "localUserUpdated": {
|
||||
await userByIdCache.delete(body.id);
|
||||
await localUserByIdCache.delete(body.id);
|
||||
@ -55,6 +68,14 @@ subscriber.on("message", async (_, data) => {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "remoteUserDeleted": {
|
||||
await userByIdCache.delete(body.id);
|
||||
const toDelete = Array.from(await uriPersonCache.getAll())
|
||||
.filter((v) => v[1]?.id === body.id)
|
||||
.map((v) => v[0]);
|
||||
await uriPersonCache.delete(...toDelete);
|
||||
break;
|
||||
}
|
||||
case "userTokenRegenerated": {
|
||||
const user = (await Users.findOneByOrFail({
|
||||
id: body.id,
|
||||
|
Loading…
Reference in New Issue
Block a user