Merge pull request 'invalidate local user cache on user update' (#9612) from supakaity/calckey:supakaity/local-user-update into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9612
This commit is contained in:
Kainoa Kanter 2023-02-12 18:43:41 +00:00
commit a6a37d6c90
3 changed files with 25 additions and 11 deletions

View file

@ -1,7 +1,7 @@
import define from "../../define.js"; import define from "../../define.js";
import { Users } from "@/models/index.js"; import { Users } from "@/models/index.js";
import { User } from "@/models/entities/user.js";
import { insertModerationLog } from "@/services/insert-moderation-log.js"; import { insertModerationLog } from "@/services/insert-moderation-log.js";
import { publishInternalEvent } from "@/services/stream.js";
export const meta = { export const meta = {
tags: ["admin"], tags: ["admin"],
@ -29,17 +29,14 @@ export default define(meta, paramDef, async (ps, me) => {
throw new Error("user is not local user"); throw new Error("user is not local user");
} }
/*if (user.isAdmin) {
throw new Error('cannot suspend admin');
}
if (user.isModerator) {
throw new Error('cannot suspend moderator');
}*/
await Users.update(user.id, { await Users.update(user.id, {
driveCapacityOverrideMb: ps.overrideMb, driveCapacityOverrideMb: ps.overrideMb,
}); });
publishInternalEvent("localUserUpdated", {
id: user.id,
});
insertModerationLog(me, "change-drive-capacity-override", { insertModerationLog(me, "change-drive-capacity-override", {
targetId: user.id, targetId: user.id,
}); });

View file

@ -7,7 +7,6 @@ import type { Note } from "@/models/entities/note.js";
import type { Antenna } from "@/models/entities/antenna.js"; import type { Antenna } from "@/models/entities/antenna.js";
import type { DriveFile } from "@/models/entities/drive-file.js"; import type { DriveFile } from "@/models/entities/drive-file.js";
import type { DriveFolder } from "@/models/entities/drive-folder.js"; import type { DriveFolder } from "@/models/entities/drive-folder.js";
import { Emoji } from "@/models/entities/emoji.js";
import type { UserList } from "@/models/entities/user-list.js"; import type { UserList } from "@/models/entities/user-list.js";
import type { MessagingMessage } from "@/models/entities/messaging-message.js"; import type { MessagingMessage } from "@/models/entities/messaging-message.js";
import type { UserGroup } from "@/models/entities/user-group.js"; import type { UserGroup } from "@/models/entities/user-group.js";
@ -23,7 +22,10 @@ export interface InternalStreamTypes {
id: User["id"]; id: User["id"];
isSuspended: User["isSuspended"]; isSuspended: User["isSuspended"];
}; };
userChangeSilencedState: { id: User["id"]; isSilenced: User["isSilenced"] }; userChangeSilencedState: {
id: User["id"];
isSilenced: User["isSilenced"];
};
userChangeModeratorState: { userChangeModeratorState: {
id: User["id"]; id: User["id"];
isModerator: User["isModerator"]; isModerator: User["isModerator"];
@ -33,7 +35,12 @@ export interface InternalStreamTypes {
oldToken: User["token"]; oldToken: User["token"];
newToken: User["token"]; newToken: User["token"];
}; };
remoteUserUpdated: { id: User["id"] }; localUserUpdated: {
id: User["id"];
};
remoteUserUpdated: {
id: User["id"];
};
webhookCreated: Webhook; webhookCreated: Webhook;
webhookDeleted: Webhook; webhookDeleted: Webhook;
webhookUpdated: Webhook; webhookUpdated: Webhook;

View file

@ -21,6 +21,16 @@ subscriber.on("message", async (_, data) => {
if (obj.channel === "internal") { if (obj.channel === "internal") {
const { type, body } = obj.message; const { type, body } = obj.message;
switch (type) { switch (type) {
case "localUserUpdated": {
userByIdCache.delete(body.id);
localUserByIdCache.delete(body.id);
localUserByNativeTokenCache.cache.forEach((v, k) => {
if (v.value?.id === body.id) {
localUserByNativeTokenCache.delete(k);
}
});
break;
}
case "userChangeSuspendedState": case "userChangeSuspendedState":
case "userChangeSilencedState": case "userChangeSilencedState":
case "userChangeModeratorState": case "userChangeModeratorState":