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 userId = typeof src === "object" ? src.id : src;
|
||||||
const user = await userDenormalizedCache.fetch(userId, () =>
|
const user = await userDenormalizedCache.fetch(
|
||||||
this.findOneOrFail({
|
userId,
|
||||||
where: { id: userId },
|
() =>
|
||||||
relations: {
|
this.findOneOrFail({
|
||||||
avatar: true,
|
where: { id: userId },
|
||||||
banner: true,
|
relations: {
|
||||||
},
|
avatar: true,
|
||||||
}),
|
banner: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
const meId = me ? me.id : null;
|
const meId = me ? me.id : null;
|
||||||
|
|
|
@ -8,6 +8,8 @@ import { MoreThan } from "typeorm";
|
||||||
import { deleteFileSync } from "@/services/drive/delete-file.js";
|
import { deleteFileSync } from "@/services/drive/delete-file.js";
|
||||||
import { sendEmail } from "@/services/send-email.js";
|
import { sendEmail } from "@/services/send-email.js";
|
||||||
import meilisearch from "@/db/meilisearch.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");
|
const logger = queueLogger.createSubLogger("delete-account");
|
||||||
|
|
||||||
|
@ -98,6 +100,8 @@ export async function deleteAccount(
|
||||||
// nop
|
// nop
|
||||||
} else {
|
} else {
|
||||||
await Users.delete(job.data.user.id);
|
await Users.delete(job.data.user.id);
|
||||||
|
await userDenormalizedCache.delete(job.data.user.id);
|
||||||
|
await userByIdCache.delete(job.data.user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Account deleted";
|
return "Account deleted";
|
||||||
|
|
|
@ -114,7 +114,7 @@ router.use(wellKnown.routes());
|
||||||
router.get("/avatar/@:acct", async (ctx) => {
|
router.get("/avatar/@:acct", async (ctx) => {
|
||||||
const { username, host } = Acct.parse(ctx.params.acct);
|
const { username, host } = Acct.parse(ctx.params.acct);
|
||||||
const userId = await acctToUserIdCache.fetchMaybe(
|
const userId = await acctToUserIdCache.fetchMaybe(
|
||||||
`${username}@${host ?? config.host}`,
|
`${username.toLowerCase()}@${host ?? config.host}`,
|
||||||
() =>
|
() =>
|
||||||
Users.findOne({
|
Users.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
@ -123,17 +123,19 @@ router.get("/avatar/@:acct", async (ctx) => {
|
||||||
isSuspended: false,
|
isSuspended: false,
|
||||||
},
|
},
|
||||||
}).then((user) => user?.id ?? undefined),
|
}).then((user) => user?.id ?? undefined),
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
ctx.redirect("/static-assets/user-unknown.png");
|
ctx.redirect("/static-assets/user-unknown.png");
|
||||||
} else {
|
} else {
|
||||||
const user = await userDenormalizedCache.fetch(userId, () =>
|
const user = await userDenormalizedCache.fetch(
|
||||||
Users.findOneOrFail({
|
userId,
|
||||||
relations: { avatar: true, banner: true },
|
() =>
|
||||||
where: { id: userId },
|
Users.findOneOrFail({
|
||||||
}),
|
relations: { avatar: true, banner: true },
|
||||||
|
where: { id: userId },
|
||||||
|
}),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
ctx.redirect(Users.getAvatarUrlSync(user));
|
ctx.redirect(Users.getAvatarUrlSync(user));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue