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

fix: getall is being called unnecessarily every time the user accesses the My Collection page #3681

Merged
merged 3 commits into from
Sep 4, 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 @@ -37,10 +37,10 @@ export const useGetFoldersQuery: useQueryFunctionType<
const myCollectionId = data?.find((f) => f.name === DEFAULT_FOLDER)?.id;
setMyCollectionId(myCollectionId);

const { getTypes } = useTypesStore.getState();
const { getTypes, types } = useTypesStore.getState();

await refreshFlows(undefined);
await getTypes();
if (!types || Object.keys(types).length === 0) await getTypes();

return foldersWithoutStarterProjects;
};
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/pages/FlowPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function FlowPage({ view }: { view?: boolean }): JSX.Element {
const { mutateAsync: refreshFlows } = useGetRefreshFlows();
const setIsLoading = useFlowsManagerStore((state) => state.setIsLoading);
const getTypes = useTypesStore((state) => state.getTypes);
const types = useTypesStore((state) => state.types);

const updatedAt = currentSavedFlow?.updated_at;

Expand Down Expand Up @@ -74,7 +75,7 @@ export default function FlowPage({ view }: { view?: boolean }): JSX.Element {
} else if (!flows) {
setIsLoading(true);
await refreshFlows(undefined);
await getTypes();
if (!types || Object.keys(types).length === 0) await getTypes();
setIsLoading(false);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/pages/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function PlaygroundPage() {
const { mutateAsync: refreshFlows } = useGetRefreshFlows();
const setIsLoading = useFlowsManagerStore((state) => state.setIsLoading);
const getTypes = useTypesStore((state) => state.getTypes);
const types = useTypesStore((state) => state.types);

// Set flow tab id
useEffect(() => {
Expand All @@ -49,7 +50,7 @@ export default function PlaygroundPage() {
} else if (!flows) {
setIsLoading(true);
await refreshFlows(undefined);
await getTypes();
if (!types || Object.keys(types).length === 0) await getTypes();
setIsLoading(false);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/pages/ViewPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function ViewPage() {
const { mutateAsync: refreshFlows } = useGetRefreshFlows();
const setIsLoading = useFlowsManagerStore((state) => state.setIsLoading);
const getTypes = useTypesStore((state) => state.getTypes);
const types = useTypesStore((state) => state.types);

// Set flow tab id
useEffect(() => {
Expand All @@ -33,7 +34,7 @@ export default function ViewPage() {
} else if (!flows) {
setIsLoading(true);
await refreshFlows(undefined);
await getTypes();
if (!types || Object.keys(types).length === 0) await getTypes();
setIsLoading(false);
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/stores/typesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ export const useTypesStore = create<TypesStoreType>((set, get) => ({
types: {},
templates: {},
data: {},
getTypes: (force_refresh: boolean = false) => {
getTypes: (force_refresh: boolean = true) => {
return new Promise<void>(async (resolve, reject) => {
const setLoading = useFlowsManagerStore.getState().setIsLoading;
getAll(force_refresh)
.then((response) => {
const data = response?.data;
useAlertStore.setState({ loading: false });
set((old) => ({
types: typesGenerator(data),
data: { ...old.data, ...data },
Expand Down
Loading