Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

perf(community): lazy-fetch server invites/audit-log only when their tab opens

Shelly#386307157be8df0b
diff --git a/src/web/src/app/c/channels/layout.tsx b/src/web/src/app/c/channels/layout.tsx
index 545efb57d..8fa7dbabf 100644
--- a/src/web/src/app/c/channels/layout.tsx
+++ b/src/web/src/app/c/channels/layout.tsx
@@ -32,11 +32,7 @@ import {
consumeVoluntaryLeave,
pickPostEjectDestination,
} from "@/components/community/eject-server"
-import {
- useInvites,
- useAuditLog,
- usePresence,
-} from "@/hooks/community/use-server-panels"
+import { usePresence } from "@/hooks/community/use-server-panels"
import { useCommunityWsStore, useOnlineUserIds } from "@/stores/community/ws"
import { useNotificationSettings } from "@/hooks/community/use-notification-settings"
import {
@@ -90,12 +86,9 @@ export default function ServerLayout({ children }: { children: ReactNode }) {
// stays stable across presence ticks.
const myMember = membersHook.members.find((m) => m.userId === currentUser.id)
const isAdmin = canManageServer(myMember?.role)
- // Fetch invites for every member (not just admins) — the invite popover on
- // the sidebar header reuses cached invites to avoid burning the per-server
- // active-invite cap. Non-admins can now create invites too, so the cache is
- // genuinely useful to them as well.
- const { invites, isLoading: invitesLoading } = useInvites(serverId, true)
- const { entries: auditLog, isLoading: auditLogLoading } = useAuditLog(serverId, isAdmin)
+ // invites + audit-log are no longer fetched here (W-LAZY, necessity plan):
+ // they're admin-only, low-frequency panel data, so ServerSettings fetches
+ // them itself only when their tab opens — never eagerly on server entry.
const presence = usePresence(serverId)
const { online: initialOnline } = presence
const notifs = useNotificationSettings()
@@ -406,10 +399,6 @@ export default function ServerLayout({ children }: { children: ReactNode }) {
membersTotal={membersHook.total}
onLoadMoreMembers={membersHook.loadMore}
onSearchMembers={membersHook.searchMembers}
- invites={invites}
- invitesLoading={invitesLoading}
- auditLog={auditLog}
- auditLogLoading={auditLogLoading}
onKickMember={(memberId) => {
kickMemberMut.mutate({ serverId, memberId }, {
onSuccess: () => toast("Member kicked"),
diff --git a/src/web/src/components/community/server-settings.tsx b/src/web/src/components/community/server-settings.tsx
index 33cb92a08..778621b0c 100644
--- a/src/web/src/components/community/server-settings.tsx
+++ b/src/web/src/components/community/server-settings.tsx
@@ -19,6 +19,7 @@ import { avatarInitial } from "@/lib/community/avatar"
import { SlugHint } from "./slug-hint"
import { previewSlug } from "@/lib/community/slug-preview"
import { tid } from "@/lib/community/testids"
+import { useInvites, useAuditLog } from "@/hooks/community/use-server-panels"
import type { SettingsSection, Member, Role, InviteRow, AuditEntry, OpenProfile } from "./_types"
import { isServerOwner } from "./_types"
@@ -32,7 +33,7 @@ function capitalize(s: string): string {
export function ServerSettings({
section, setSection, onClose, serverId, serverName, serverDescription, serverIcon,
members, membersLoading, membersLoadingMore, membersHasMore, membersTotal, onLoadMoreMembers, onSearchMembers,
- invites, invitesLoading, auditLog, auditLogLoading, onOpenProfile,
+ onOpenProfile,
onKickMember, onSetRole, onRevokeInvite, onCopyInvite, onDeleteServer, onUploadIcon, onUpdateServer, notifLevel, onSetNotifLevel,
}: {
section: SettingsSection
@@ -49,10 +50,6 @@ export function ServerSettings({
membersTotal?: number
onLoadMoreMembers?: () => void
onSearchMembers?: (q: string) => void
- invites: InviteRow[]
- invitesLoading?: boolean
- auditLog: AuditEntry[]
- auditLogLoading?: boolean
onOpenProfile?: OpenProfile
onKickMember?: (memberId: string) => void
onSetRole?: (memberId: string, role: Role) => void
@@ -65,6 +62,16 @@ export function ServerSettings({
onSetNotifLevel?: (l: string) => void
}) {
const [confirmDelete, setConfirmDelete] = useState(false)
+
+ // W-LAZY (necessity plan): invites + audit-log are low-frequency, admin-only
+ // panel data — fetch them ONLY when their tab is actually open, never at
+ // mount, never via WS (Gus, 架构 #25). Gating `enabled` on the active section
+ // means opening Settings on any other tab fetches neither; switching TO the
+ // Invites / Audit tab fetches it fresh then. Previously both were eager-
+ // prefetched in the ServerLayout on every server entry.
+ const { invites, isLoading: invitesLoading } = useInvites(serverId, section === "invites")
+ const { entries: auditLog, isLoading: auditLogLoading } = useAuditLog(serverId, section === "audit")
+
const nav: { id: SettingsSection; label: string; icon: LucideIcon }[] = [
{ id: "overview", label: "Overview", icon: Settings },
{ id: "members", label: "Members", icon: Users },