fix: properly update cache
This commit is contained in:
parent
8e0b0c7cb9
commit
0b23a5adaa
8 changed files with 74 additions and 11 deletions
|
@ -48,7 +48,10 @@ export default async (
|
|||
if (isNativeToken(token)) {
|
||||
const user = await localUserByNativeTokenCache.fetch(
|
||||
token,
|
||||
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>,
|
||||
() =>
|
||||
Users.findOneBy({
|
||||
token: token as string,
|
||||
}) as Promise<ILocalUser | null>,
|
||||
true,
|
||||
);
|
||||
|
||||
|
@ -83,14 +86,11 @@ export default async (
|
|||
Users.findOneBy({
|
||||
id: accessToken.userId,
|
||||
}) as Promise<ILocalUser>,
|
||||
true,
|
||||
);
|
||||
|
||||
if (accessToken.appId) {
|
||||
const app = await appCache.fetch(
|
||||
accessToken.appId,
|
||||
() => Apps.findOneByOrFail({ id: accessToken.appId! }),
|
||||
true,
|
||||
const app = await appCache.fetch(accessToken.appId, () =>
|
||||
Apps.findOneByOrFail({ id: accessToken.appId as string }),
|
||||
);
|
||||
|
||||
return [
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import define from "../../../define.js";
|
||||
import { Users } from "@/models/index.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -28,6 +33,9 @@ export default define(meta, paramDef, async (ps) => {
|
|||
throw new Error("cannot mark as moderator if admin user");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await localUserByIdCache.delete(user.id);
|
||||
await Users.update(user.id, {
|
||||
isModerator: true,
|
||||
});
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import define from "../../../define.js";
|
||||
import { Users } from "@/models/index.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -24,6 +29,9 @@ export default define(meta, paramDef, async (ps) => {
|
|||
throw new Error("user not found");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await localUserByIdCache.delete(user.id);
|
||||
await Users.update(user.id, {
|
||||
isModerator: false,
|
||||
});
|
||||
|
|
|
@ -2,6 +2,11 @@ import define from "../../define.js";
|
|||
import { Users } from "@/models/index.js";
|
||||
import { insertModerationLog } from "@/services/insert-moderation-log.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -29,6 +34,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
throw new Error("cannot silence admin");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await localUserByIdCache.delete(user.id);
|
||||
await Users.update(user.id, {
|
||||
isSilenced: true,
|
||||
});
|
||||
|
|
|
@ -7,6 +7,11 @@ import { doPostSuspend } from "@/services/suspend-user.js";
|
|||
import { publishUserEvent } from "@/services/stream.js";
|
||||
import { scyllaClient } from "@/db/scylla.js";
|
||||
import { SuspendedUsersCache } from "@/misc/cache.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -38,6 +43,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
throw new Error("cannot suspend moderator");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await SuspendedUsersCache.init().then((cache) => cache.add(user.id));
|
||||
await Users.update(user.id, {
|
||||
isSuspended: true,
|
||||
|
@ -49,6 +56,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
|
||||
// Terminate streaming
|
||||
if (Users.isLocalUser(user)) {
|
||||
await localUserByIdCache.delete(user.id);
|
||||
publishUserEvent(user.id, "terminate", {});
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@ import define from "../../define.js";
|
|||
import { Users } from "@/models/index.js";
|
||||
import { insertModerationLog } from "@/services/insert-moderation-log.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -25,6 +30,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
throw new Error("user not found");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await localUserByIdCache.delete(user.id);
|
||||
await Users.update(user.id, {
|
||||
isSilenced: false,
|
||||
});
|
||||
|
|
|
@ -3,6 +3,11 @@ import define from "../../define.js";
|
|||
import { Users } from "@/models/index.js";
|
||||
import { insertModerationLog } from "@/services/insert-moderation-log.js";
|
||||
import { doPostUnsuspend } from "@/services/unsuspend-user.js";
|
||||
import {
|
||||
localUserByIdCache,
|
||||
userByIdCache,
|
||||
userDenormalizedCache,
|
||||
} from "@/services/user-cache.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -26,6 +31,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
throw new Error("user not found");
|
||||
}
|
||||
|
||||
await userDenormalizedCache.delete(user.id);
|
||||
await userByIdCache.delete(user.id);
|
||||
await localUserByIdCache.delete(user.id);
|
||||
await SuspendedUsersCache.init().then((cache) => cache.delete(user.id));
|
||||
await Users.update(user.id, {
|
||||
isSuspended: false,
|
||||
|
|
|
@ -35,11 +35,26 @@ export default async function (
|
|||
searchCriteria.replyId = IsNull();
|
||||
}
|
||||
|
||||
const notes = await Notes.find({
|
||||
let notes: Note[] = [];
|
||||
if (scyllaClient) {
|
||||
const query = [prepared.note.select.byUserId, "LIMIT ?"];
|
||||
notes = await scyllaClient
|
||||
.execute(
|
||||
query.join(" "),
|
||||
[user.id, Math.min(history, config.scylla?.queryLimit ?? 100)],
|
||||
{ prepare: true },
|
||||
)
|
||||
.then((result) => result.rows.map(parseScyllaNote));
|
||||
notes = notes.filter(
|
||||
(note) => !(!renotes && note.renoteId) && !(!replies && note.replyId),
|
||||
);
|
||||
} else {
|
||||
notes = await Notes.find({
|
||||
where: searchCriteria,
|
||||
order: { createdAt: -1 },
|
||||
take: history,
|
||||
});
|
||||
}
|
||||
|
||||
const feed = new Feed({
|
||||
id: author.link,
|
||||
|
|
Loading…
Reference in a new issue