Skip to content

Commit

Permalink
Merge pull request #18 from pipecat-ai/cst/reduce-fetches
Browse files Browse the repository at this point in the history
Reduce fetches
  • Loading branch information
jptaylor authored Nov 19, 2024
2 parents 088f9ba + d0c12fb commit 6f1e0d9
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const ConversationList = ({
return await searchConversations(workspaceId, searchQuery, pageParam);
return await getConversations(workspaceId, pageParam);
},
refetchOnMount: false,
});

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { queryClient } from "@/components/QueryClientProvider";
import { Button } from "@/components/ui/button";
import {
Dialog,
Expand Down Expand Up @@ -48,10 +47,7 @@ export default function DeleteConversationModal({
}),
});
if (response.ok) {
queryClient.invalidateQueries({
queryKey: ["conversations", workspaceId],
type: "all",
});
emitter.emit("updateSidebar");
emitter.emit("showPageTransitionLoader");
push(`/${workspaceId}`);
emitter.emit("updateSidebar");
Expand Down
1 change: 0 additions & 1 deletion clients/web/app/(authenticated)/[workspaceId]/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default function Sidebar({
const updateSidebar = () =>
queryClient.invalidateQueries({
queryKey: ["conversations", workspace?.workspace_id],
type: "all",
});
const handleResize = () => {
if (window.innerWidth >= 1024) setIsOpen(false);
Expand Down
6 changes: 1 addition & 5 deletions clients/web/components/ChatControls.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import ExpiryCountdown from "@/components/ExpiryCountdown";
import { queryClient } from "@/components/QueryClientProvider";
import emitter from "@/lib/eventEmitter";
import { cn } from "@/lib/utils";
import {
Expand Down Expand Up @@ -160,10 +159,7 @@ const ChatControls: React.FC<Props> = ({
);

const invalidateAndRedirect = async (redirect: string) => {
await queryClient.invalidateQueries({
queryKey: ["conversations", workspaceId],
type: "all",
});
emitter.emit("updateSidebar");
emitter.emit("showPageTransitionLoader");
push(redirect);
};
Expand Down
3 changes: 0 additions & 3 deletions clients/web/components/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ interface Props {
conversationId: string;
messages: Message[];
structuredWorkspace: WorkspaceStructuredData;
workspaceId: string;
}

export default function ChatMessages({
autoscroll = true,
conversationId,
messages,
structuredWorkspace,
workspaceId,
}: Props) {
const [isBotSpeaking, setIsBotSpeaking] = useState(false);

Expand Down Expand Up @@ -65,7 +63,6 @@ export default function ChatMessages({
isBotSpeaking={isBotSpeaking}
messages={messages}
structuredWorkspace={structuredWorkspace}
workspaceId={workspaceId}
/>
</div>
);
Expand Down
1 change: 0 additions & 1 deletion clients/web/components/ClientPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export default function ClientPage({
conversationId={conversationId}
messages={messages}
structuredWorkspace={structuredWorkspace}
workspaceId={workspaceId}
/>
) : (
<div className="flex flex-col gap-4 items-center justify-center h-full my-auto">
Expand Down
14 changes: 2 additions & 12 deletions clients/web/components/LiveMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "react";

import ChatMessage from "@/components/ChatMessage";
import { queryClient } from "@/components/QueryClientProvider";
import emitter from "@/lib/eventEmitter";
import { LLMMessageRole } from "@/lib/llm";
import type { Message } from "@/lib/messages";
Expand All @@ -35,7 +34,6 @@ interface Props {
isBotSpeaking?: boolean;
messages: Message[];
structuredWorkspace: WorkspaceStructuredData;
workspaceId: string;
}

const addNewLinesBeforeCodeblocks = (markdown: string) =>
Expand All @@ -52,20 +50,12 @@ interface MessageChunk {
updatedAt?: Date;
}

const revalidateConversation = async (workspaceId: string) => {
queryClient.invalidateQueries({
queryKey: ["conversations", workspaceId],
type: "all",
});
};

export default function LiveMessages({
autoscroll,
conversationId,
isBotSpeaking,
messages,
structuredWorkspace,
workspaceId,
}: Props) {
const { refresh } = useRouter();
const [liveMessages, setLiveMessages] = useState<LiveMessage[]>([]);
Expand Down Expand Up @@ -170,9 +160,9 @@ export default function LiveMessages({
const isTextResponse = useRef(false);

const revalidateAndRefresh = useCallback(async () => {
await revalidateConversation(workspaceId);
emitter.emit("updateSidebar");
refresh();
}, [refresh, workspaceId]);
}, [refresh]);

useRTVIClientEvent(
RTVIEvent.BotLlmStarted,
Expand Down
15 changes: 2 additions & 13 deletions clients/web/lib/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,8 @@ export async function getWorkspaces() {

export async function getWorkspace(id: string) {
try {
const apiClient = await getApiClient();
const response =
await apiClient.api.getWorkspaceApiWorkspacesWorkspaceIdGet(id);
const json = await response.json();
if (response.ok) {
const cleanedUp = structuredClone<WorkspaceModel>(json);
delete cleanedUp.config.api_keys;
return cleanedUp;
} else {
throw new Error(
`Error fetching workspace: ${response.status} ${response.statusText}`
);
}
const workspaces = await getWorkspaces();
return workspaces.find(ws => ws.workspace_id === id);
} catch (e) {
console.error(e);
return null;
Expand Down

0 comments on commit 6f1e0d9

Please sign in to comment.