Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OPIK-448] [FE] UI on editing feedback score is slow #729

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ const useTraceFeedbackScoreDeleteMutation = () => {

const deleteMutation = generateDeleteMutation(params.name);

// make optimistic update for compare experiments
setExperimentsCompareCache(queryClient, traceParams, deleteMutation);

if (params.spanId) {
// make optimistic update for spans
setSpansCache(
await setSpansCache(
queryClient,
{
traceId: params.traceId,
Expand All @@ -76,11 +73,18 @@ const useTraceFeedbackScoreDeleteMutation = () => {
deleteMutation,
);
} else {
// make optimistic update for compare experiments
await setExperimentsCompareCache(
queryClient,
traceParams,
deleteMutation,
);

// make optimistic update for traces
setTracesCache(queryClient, traceParams, deleteMutation);
await setTracesCache(queryClient, traceParams, deleteMutation);

// make optimistic update for trace
setTraceCache(queryClient, traceParams, deleteMutation);
await setTraceCache(queryClient, traceParams, deleteMutation);
}
},
onSettled: async (data, error, variables) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ const useTraceFeedbackScoreSetMutation = () => {
source: FEEDBACK_SCORE_TYPE.ui,
});

// make optimistic update for compare experiments
setExperimentsCompareCache(queryClient, traceParams, updateMutation);

if (params.spanId) {
// make optimistic update for spans
setSpansCache(
await setSpansCache(
queryClient,
{
traceId: params.traceId,
Expand All @@ -91,11 +88,18 @@ const useTraceFeedbackScoreSetMutation = () => {
updateMutation,
);
} else {
// make optimistic update for compare experiments
await setExperimentsCompareCache(
queryClient,
traceParams,
updateMutation,
);

// make optimistic update for traces
setTracesCache(queryClient, traceParams, updateMutation);
await setTracesCache(queryClient, traceParams, updateMutation);

// make optimistic update for trace
setTraceCache(queryClient, traceParams, updateMutation);
await setTraceCache(queryClient, traceParams, updateMutation);
}
},
onSettled: async (data, error, variables) => {
Expand Down
16 changes: 12 additions & 4 deletions apps/opik-frontend/src/lib/feedback-scores.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { UseCompareExperimentsListResponse } from "@/api/datasets/useCompareExpe
import { UseTracesListResponse } from "@/api/traces/useTracesList";
import { UseSpansListResponse } from "@/api/traces/useSpansList";

export const setExperimentsCompareCache = (
export const setExperimentsCompareCache = async (
queryClient: QueryClient,
params: { traceId: string },
mutate: (
Expand All @@ -26,6 +26,8 @@ export const setExperimentsCompareCache = (

if (!queryKey) return;

await queryClient.cancelQueries({ queryKey });

queryClient.setQueryData(
queryKey,
(originalData: UseCompareExperimentsListResponse) => {
Expand All @@ -52,7 +54,7 @@ export const setExperimentsCompareCache = (
);
};

export const setTracesCache = (
export const setTracesCache = async (
queryClient: QueryClient,
params: { traceId: string },
mutate: (
Expand All @@ -68,6 +70,8 @@ export const setTracesCache = (

if (!queryKey) return;

await queryClient.cancelQueries({ queryKey });

queryClient.setQueryData(queryKey, (originalData: UseTracesListResponse) => {
return {
...originalData,
Expand All @@ -84,7 +88,7 @@ export const setTracesCache = (
});
};

export const setSpansCache = (
export const setSpansCache = async (
queryClient: QueryClient,
params: { traceId: string; spanId: string },
mutate: (
Expand All @@ -100,6 +104,8 @@ export const setSpansCache = (

if (!queryKey) return;

await queryClient.cancelQueries({ queryKey });

queryClient.setQueryData(queryKey, (originalData: UseSpansListResponse) => {
return {
...originalData,
Expand All @@ -116,7 +122,7 @@ export const setSpansCache = (
});
};

export const setTraceCache = (
export const setTraceCache = async (
queryClient: QueryClient,
params: { traceId: string },
mutate: (
Expand All @@ -132,6 +138,8 @@ export const setTraceCache = (

if (!queryKey) return;

await queryClient.cancelQueries({ queryKey });

queryClient.setQueryData(queryKey, (originalData: Trace) => {
return {
...originalData,
Expand Down