fix: renew cache ttl and purge with account deletion
This commit is contained in:
parent
9ff89d95cd
commit
680056cfd9
3 changed files with 24 additions and 15 deletions
|
@ -384,14 +384,17 @@ export const UserRepository = db.getRepository(User).extend({
|
|||
);
|
||||
|
||||
const userId = typeof src === "object" ? src.id : src;
|
||||
const user = await userDenormalizedCache.fetch(userId, () =>
|
||||
this.findOneOrFail({
|
||||
where: { id: userId },
|
||||
relations: {
|
||||
avatar: true,
|
||||
banner: true,
|
||||
},
|
||||
}),
|
||||
const user = await userDenormalizedCache.fetch(
|
||||
userId,
|
||||
() =>
|
||||
this.findOneOrFail({
|
||||
where: { id: userId },
|
||||
relations: {
|
||||
avatar: true,
|
||||
banner: true,
|
||||
},
|
||||
}),
|
||||
true,
|
||||
);
|
||||
|
||||
const meId = me ? me.id : null;
|
||||
|
|
|
@ -8,6 +8,8 @@ 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 { acctToUserIdCache, userByIdCache, userDenormalizedCache } from "@/services/user-cache.js";
|
||||
import config from "@/config/index.js";
|
||||
|
||||
const logger = queueLogger.createSubLogger("delete-account");
|
||||
|
||||
|
@ -98,6 +100,8 @@ export async function deleteAccount(
|
|||
// nop
|
||||
} else {
|
||||
await Users.delete(job.data.user.id);
|
||||
await userDenormalizedCache.delete(job.data.user.id);
|
||||
await userByIdCache.delete(job.data.user.id);
|
||||
}
|
||||
|
||||
return "Account deleted";
|
||||
|
|
|
@ -114,7 +114,7 @@ router.use(wellKnown.routes());
|
|||
router.get("/avatar/@:acct", async (ctx) => {
|
||||
const { username, host } = Acct.parse(ctx.params.acct);
|
||||
const userId = await acctToUserIdCache.fetchMaybe(
|
||||
`${username}@${host ?? config.host}`,
|
||||
`${username.toLowerCase()}@${host ?? config.host}`,
|
||||
() =>
|
||||
Users.findOne({
|
||||
where: {
|
||||
|
@ -123,17 +123,19 @@ router.get("/avatar/@:acct", async (ctx) => {
|
|||
isSuspended: false,
|
||||
},
|
||||
}).then((user) => user?.id ?? undefined),
|
||||
true,
|
||||
);
|
||||
|
||||
if (!userId) {
|
||||
ctx.redirect("/static-assets/user-unknown.png");
|
||||
} else {
|
||||
const user = await userDenormalizedCache.fetch(userId, () =>
|
||||
Users.findOneOrFail({
|
||||
relations: { avatar: true, banner: true },
|
||||
where: { id: userId },
|
||||
}),
|
||||
const user = await userDenormalizedCache.fetch(
|
||||
userId,
|
||||
() =>
|
||||
Users.findOneOrFail({
|
||||
relations: { avatar: true, banner: true },
|
||||
where: { id: userId },
|
||||
}),
|
||||
true,
|
||||
);
|
||||
ctx.redirect(Users.getAvatarUrlSync(user));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue