perf: short-circuit static doctor channel capabilities

This commit is contained in:
Peter Steinberger
2026-04-11 07:03:48 +01:00
parent 9e3f4ed22f
commit e2d93fb5bc

View File

@@ -1,5 +1,6 @@
import { getBundledChannelPlugin } from "../../channels/plugins/bundled.js";
import { getChannelPlugin } from "../../channels/plugins/index.js";
import { normalizeAnyChannelId } from "../../channels/registry.js";
import type { AllowFromMode } from "./shared/allow-from-mode.types.js";
export type DoctorGroupModel = "sender" | "route" | "hybrid";
@@ -18,12 +19,42 @@ const DEFAULT_DOCTOR_CHANNEL_CAPABILITIES: DoctorChannelCapabilities = {
warnOnEmptyGroupSenderAllowlist: true,
};
const STATIC_DOCTOR_CHANNEL_CAPABILITIES: Readonly<Record<string, DoctorChannelCapabilities>> = {
matrix: {
dmAllowFromMode: "nestedOnly",
groupModel: "sender",
groupAllowFromFallbackToAllowFrom: false,
warnOnEmptyGroupSenderAllowlist: true,
},
msteams: {
dmAllowFromMode: "topOnly",
groupModel: "hybrid",
groupAllowFromFallbackToAllowFrom: false,
warnOnEmptyGroupSenderAllowlist: true,
},
zalouser: {
dmAllowFromMode: "topOnly",
groupModel: "hybrid",
groupAllowFromFallbackToAllowFrom: false,
warnOnEmptyGroupSenderAllowlist: false,
},
};
export function getDoctorChannelCapabilities(channelName?: string): DoctorChannelCapabilities {
if (!channelName) {
return DEFAULT_DOCTOR_CHANNEL_CAPABILITIES;
}
const staticCapabilities = STATIC_DOCTOR_CHANNEL_CAPABILITIES[channelName];
if (staticCapabilities) {
return staticCapabilities;
}
const registeredChannelId = normalizeAnyChannelId(channelName);
if (!registeredChannelId) {
return DEFAULT_DOCTOR_CHANNEL_CAPABILITIES;
}
const pluginDoctor =
getChannelPlugin(channelName)?.doctor ?? getBundledChannelPlugin(channelName)?.doctor;
getChannelPlugin(registeredChannelId)?.doctor ??
getBundledChannelPlugin(registeredChannelId)?.doctor;
if (pluginDoctor) {
return {
dmAllowFromMode: