From 4bb5aba70e9144d710ed1182ecbb445575214af6 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 14 Mar 2024 07:35:39 +1100 Subject: [PATCH] feat(ui): only fetch TIs on first load, add comment --- .../listeners/socketio/socketConnected.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected.ts index daae46542f..2540362201 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketConnected.ts @@ -18,9 +18,6 @@ export const addSocketConnectedEventListener = (startAppListening: AppStartListe effect: async (action, { dispatch, getState, cancelActiveListeners, delay }) => { log.debug('Connected'); - // query TIs so they are ready if user opens trigger phrases - dispatch(modelsApi.endpoints.getTextualInversionModels.initiate()); - /** * The rest of this listener has recovery logic for when the socket disconnects and reconnects. * @@ -33,6 +30,12 @@ export const addSocketConnectedEventListener = (startAppListening: AppStartListe // Bail on the recovery logic if this is the first connection - we don't need to recover anything if ($isFirstConnection.get()) { + // The TI models are used in a component that is not always rendered, so when users open the prompt triggers + // box has a delay while it does the initial fetch. We need to both pre-fetch the data and maintain an RTK + // Query subscription to it, so the cache doesn't clear itself when the user closes the prompt triggers box. + // So, we explicitly do not unsubscribe from this query! + dispatch(modelsApi.endpoints.getTextualInversionModels.initiate()); + $isFirstConnection.set(false); return; }