mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
Merge pull request #1183 from mvanhorn/perf/remove-simple-usememo
perf: remove unnecessary useMemo wrapping simple boolean expressions
This commit is contained in:
commit
d73658a8f3
5 changed files with 18 additions and 49 deletions
|
|
@ -4,7 +4,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|||
import { useAtomValue, useSetAtom } from "jotai";
|
||||
import { Earth, User, Users } from "lucide-react";
|
||||
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { currentThreadAtom, setThreadVisibilityAtom } from "@/atoms/chat/current-thread.atom";
|
||||
import { myAccessAtom } from "@/atoms/members/members-query.atoms";
|
||||
|
|
@ -63,11 +63,8 @@ export function ChatShareButton({ thread, onVisibilityChange, className }: ChatS
|
|||
|
||||
// Permission check for public sharing
|
||||
const { data: access } = useAtomValue(myAccessAtom);
|
||||
const canCreatePublicLink = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("public_sharing:create") ?? false;
|
||||
}, [access]);
|
||||
const canCreatePublicLink =
|
||||
!!access && (access.is_owner || (access.permissions?.includes("public_sharing:create") ?? false));
|
||||
|
||||
// Query to check if thread has public snapshots
|
||||
const { data: snapshotsData } = useQuery({
|
||||
|
|
|
|||
|
|
@ -121,9 +121,8 @@ export function ModelSelector({
|
|||
return llmUserConfigs?.find((c) => c.id === agentLlmId) ?? null;
|
||||
}, [preferences, llmGlobalConfigs, llmUserConfigs]);
|
||||
|
||||
const isLLMAutoMode = useMemo(() => {
|
||||
return currentLLMConfig && "is_auto_mode" in currentLLMConfig && currentLLMConfig.is_auto_mode;
|
||||
}, [currentLLMConfig]);
|
||||
const isLLMAutoMode =
|
||||
currentLLMConfig && "is_auto_mode" in currentLLMConfig && currentLLMConfig.is_auto_mode;
|
||||
|
||||
// ─── Image current config ───
|
||||
const currentImageConfig = useMemo(() => {
|
||||
|
|
@ -135,11 +134,8 @@ export function ModelSelector({
|
|||
return imageUserConfigs?.find((c) => c.id === id) ?? null;
|
||||
}, [preferences, imageGlobalConfigs, imageUserConfigs]);
|
||||
|
||||
const isImageAutoMode = useMemo(() => {
|
||||
return (
|
||||
currentImageConfig && "is_auto_mode" in currentImageConfig && currentImageConfig.is_auto_mode
|
||||
);
|
||||
}, [currentImageConfig]);
|
||||
const isImageAutoMode =
|
||||
currentImageConfig && "is_auto_mode" in currentImageConfig && currentImageConfig.is_auto_mode;
|
||||
|
||||
// ─── Vision current config ───
|
||||
const currentVisionConfig = useMemo(() => {
|
||||
|
|
|
|||
|
|
@ -43,17 +43,11 @@ export function PublicChatSnapshotsManager({
|
|||
|
||||
// Permissions
|
||||
const { data: access } = useAtomValue(myAccessAtom);
|
||||
const canView = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("public_sharing:view") ?? false;
|
||||
}, [access]);
|
||||
const canView =
|
||||
!!access && (access.is_owner || (access.permissions?.includes("public_sharing:view") ?? false));
|
||||
|
||||
const canDelete = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("public_sharing:delete") ?? false;
|
||||
}, [access]);
|
||||
const canDelete =
|
||||
!!access && (access.is_owner || (access.permissions?.includes("public_sharing:delete") ?? false));
|
||||
|
||||
// Mutations
|
||||
const { mutateAsync: deleteSnapshot } = useAtomValue(deletePublicChatSnapshotMutationAtom);
|
||||
|
|
|
|||
|
|
@ -78,16 +78,10 @@ export function ImageModelManager({ searchSpaceId }: ImageModelManagerProps) {
|
|||
}, [members]);
|
||||
|
||||
const { data: access } = useAtomValue(myAccessAtom);
|
||||
const canCreate = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("image_generations:create") ?? false;
|
||||
}, [access]);
|
||||
const canDelete = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("image_generations:delete") ?? false;
|
||||
}, [access]);
|
||||
const canCreate =
|
||||
!!access && (access.is_owner || (access.permissions?.includes("image_generations:create") ?? false));
|
||||
const canDelete =
|
||||
!!access && (access.is_owner || (access.permissions?.includes("image_generations:delete") ?? false));
|
||||
const canUpdate = canCreate;
|
||||
const isReadOnly = !canCreate && !canDelete;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,21 +89,9 @@ export function ModelConfigManager({ searchSpaceId }: ModelConfigManagerProps) {
|
|||
|
||||
// Permissions
|
||||
const { data: access } = useAtomValue(myAccessAtom);
|
||||
const canCreate = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("llm_configs:create") ?? false;
|
||||
}, [access]);
|
||||
const canUpdate = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("llm_configs:update") ?? false;
|
||||
}, [access]);
|
||||
const canDelete = useMemo(() => {
|
||||
if (!access) return false;
|
||||
if (access.is_owner) return true;
|
||||
return access.permissions?.includes("llm_configs:delete") ?? false;
|
||||
}, [access]);
|
||||
const canCreate = !!access && (access.is_owner || (access.permissions?.includes("llm_configs:create") ?? false));
|
||||
const canUpdate = !!access && (access.is_owner || (access.permissions?.includes("llm_configs:update") ?? false));
|
||||
const canDelete = !!access && (access.is_owner || (access.permissions?.includes("llm_configs:delete") ?? false));
|
||||
const isReadOnly = !canCreate && !canUpdate && !canDelete;
|
||||
|
||||
// Local state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue