mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
feat(ui): create debounced metadata/workflow query hooks
Also added config options for metadata and workflow debounce times (`metadataFetchDebounce` & `workflowFetchDebounce`). Falls back to 0 if not provided. In OSS, because we have no major latency concerns, the debounce is 0. But in other environments, it may be desirable to set this to something like 300ms.
This commit is contained in:
@@ -7,7 +7,6 @@ export const workflowsApi = api.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
getWorkflow: build.query<Workflow | undefined, string>({
|
||||
query: (workflow_id) => `workflows/i/${workflow_id}`,
|
||||
keepUnusedDataFor: 86400, // 24 hours
|
||||
providesTags: (result, error, workflow_id) => [
|
||||
{ type: 'Workflow', id: workflow_id },
|
||||
],
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { skipToken } from '@reduxjs/toolkit/query';
|
||||
import { useDebounce } from 'use-debounce';
|
||||
import { useGetImageMetadataQuery } from '../endpoints/images';
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
|
||||
export const useDebouncedMetadata = (imageName?: string | null) => {
|
||||
const metadataFetchDebounce = useAppSelector(
|
||||
(state) => state.config.metadataFetchDebounce
|
||||
);
|
||||
|
||||
const [debouncedImageName] = useDebounce(
|
||||
imageName,
|
||||
metadataFetchDebounce ?? 0
|
||||
);
|
||||
|
||||
const { data: metadata, isLoading } = useGetImageMetadataQuery(
|
||||
debouncedImageName ?? skipToken
|
||||
);
|
||||
|
||||
return { metadata, isLoading };
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import { skipToken } from '@reduxjs/toolkit/query';
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
import { useDebounce } from 'use-debounce';
|
||||
import { useGetWorkflowQuery } from '../endpoints/workflows';
|
||||
|
||||
export const useDebouncedWorkflow = (workflowId?: string | null) => {
|
||||
const workflowFetchDebounce = useAppSelector(
|
||||
(state) => state.config.workflowFetchDebounce
|
||||
);
|
||||
|
||||
const [debouncedWorkflowID] = useDebounce(
|
||||
workflowId,
|
||||
workflowFetchDebounce ?? 0
|
||||
);
|
||||
|
||||
const { data: workflow, isLoading } = useGetWorkflowQuery(
|
||||
debouncedWorkflowID ?? skipToken
|
||||
);
|
||||
|
||||
return { workflow, isLoading };
|
||||
};
|
||||
Reference in New Issue
Block a user