perf(web): avoid visit writes during thread streaming
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
8b5469863a
commit
0381ec7e53
2 files changed
+21
-23
No files matched your search
@@ -93,7 +93,6 @@ import {
|
||||
togglePendingUserInputOptionSelection,
|
||||
type PendingUserInputDraftAnswer,
|
||||
} from "../pendingUserInput";
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
import {
|
||||
buildPlanImplementationThreadTitle,
|
||||
buildPlanImplementationPrompt,
|
||||
@@ -109,6 +108,7 @@ import {
|
||||
type Thread,
|
||||
type TurnDiffSummary,
|
||||
} from "../types";
|
||||
import { useMarkActiveThreadVisited } from "../hooks/useMarkActiveThreadVisited";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
|
||||
import { isCommandPaletteOpen } from "../commandPaletteContext";
|
||||
@@ -1036,9 +1036,9 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
const composerDraftTarget: ScopedThreadRef | DraftId =
|
||||
routeKind === "server" ? routeThreadRef : props.draftId;
|
||||
const serverThread = useThread(routeKind === "server" ? routeThreadRef : null);
|
||||
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
|
||||
const activeThreadLastVisitedAt = useUiStateStore((store) =>
|
||||
routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined,
|
||||
useMarkActiveThreadVisited(
|
||||
routeKind === "server" ? routeThreadKey : null,
|
||||
serverThread?.latestTurn?.completedAt ?? null,
|
||||
);
|
||||
const settings = useEnvironmentSettings(environmentId);
|
||||
const setStickyComposerModelSelection = useComposerDraftStore(
|
||||
@@ -1599,25 +1599,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
[openOrReuseProjectDraftThread],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!serverThread?.id) return;
|
||||
const threadUpdatedAt = Date.parse(serverThread.updatedAt);
|
||||
if (Number.isNaN(threadUpdatedAt)) return;
|
||||
const lastVisitedAt = activeThreadLastVisitedAt ? Date.parse(activeThreadLastVisitedAt) : NaN;
|
||||
if (!Number.isNaN(lastVisitedAt) && lastVisitedAt >= threadUpdatedAt) return;
|
||||
|
||||
markThreadVisited(
|
||||
scopedThreadKey(scopeThreadRef(serverThread.environmentId, serverThread.id)),
|
||||
serverThread.updatedAt,
|
||||
);
|
||||
}, [
|
||||
activeThreadLastVisitedAt,
|
||||
markThreadVisited,
|
||||
serverThread?.environmentId,
|
||||
serverThread?.id,
|
||||
serverThread?.updatedAt,
|
||||
]);
|
||||
|
||||
const selectedProviderByThreadId = composerActiveProvider ?? null;
|
||||
const threadProvider =
|
||||
activeThread?.modelSelection.instanceId ??
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
|
||||
export function useMarkActiveThreadVisited(
|
||||
threadKey: string | null,
|
||||
latestTurnCompletedAt: string | null,
|
||||
): void {
|
||||
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
|
||||
|
||||
useEffect(() => {
|
||||
if (threadKey === null || latestTurnCompletedAt === null) {
|
||||
return;
|
||||
}
|
||||
markThreadVisited(threadKey, latestTurnCompletedAt);
|
||||
}, [latestTurnCompletedAt, markThreadVisited, threadKey]);
|
||||
}
|
||||
Reference in new issue
Block a user