perf: cache broadcast audience counts

This commit is contained in:
3252a8
2026-06-07 23:15:44 +03:00
parent d1c4a6de80
commit 4b8f939a25
7 changed files with 244 additions and 28 deletions
+1
View File
@@ -518,6 +518,7 @@
if (typeof window !== "undefined") {
window.addEventListener("popstate", onPopState);
}
void broadcastStore.loadCounts();
return () => {
if (motionMql) motionMql.removeEventListener("change", onMotionChange);
if (compactMql) {
@@ -8,15 +8,23 @@
export let at;
const broadcastStore = getContext("broadcastStore");
$: ({ broadcastTarget, broadcastText, broadcastBusy, broadcastResult, broadcastCounts } =
$broadcastStore);
$: ({
broadcastTarget,
broadcastText,
broadcastBusy,
broadcastResult,
broadcastCounts,
broadcastCountsLoading,
} = $broadcastStore);
const BROADCAST_TARGET_OPTIONS = broadcastStore.BROADCAST_TARGET_OPTIONS;
// Append the resolved audience size to each option once counts are loaded.
$: targetOptions = BROADCAST_TARGET_OPTIONS.map((option) => {
const count = broadcastCounts?.[option.value];
return count == null ? option : { ...option, label: `${option.label} (${count})` };
if (count != null) return { ...option, label: `${option.label} (${count})` };
if (broadcastCountsLoading) return { ...option, label: `${option.label} (...)` };
return option;
});
onMount(() => {