feat(ui): invalidate cache for queue item on status change

This query is only subscribed-to in the `QueueItemDetail` component - when is rendered only when the user clicks on a queue item in the queue. Invalidating this tag instead of optimistically updating it won't cause any meaningful change to network traffic.
This commit is contained in:
psychedelicious 2024-05-20 18:23:01 +10:00
parent 12ce095bb2
commit 8eb5316c9f

View File

@ -14,7 +14,7 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
actionCreator: socketQueueItemStatusChanged, actionCreator: socketQueueItemStatusChanged,
effect: async (action, { dispatch }) => { effect: async (action, { dispatch }) => {
// we've got new status for the queue item, batch and queue // we've got new status for the queue item, batch and queue
const { item_id, status, started_at, updated_at, error, completed_at, created_at, batch_status, queue_status } = const { item_id, status, started_at, updated_at, error, completed_at, batch_status, queue_status } =
action.payload.data; action.payload.data;
log.debug(action.payload, `Queue item ${item_id} status updated: ${status}`); log.debug(action.payload, `Queue item ${item_id} status updated: ${status}`);
@ -50,27 +50,15 @@ export const addSocketQueueItemStatusChangedEventListener = (startAppListening:
queueApi.util.updateQueryData('getBatchStatus', { batch_id: batch_status.batch_id }, () => batch_status) queueApi.util.updateQueryData('getBatchStatus', { batch_id: batch_status.batch_id }, () => batch_status)
); );
// Update the queue item status (this is the full queue item, including the session)
dispatch(
queueApi.util.updateQueryData('getQueueItem', item_id, (draft) => {
if (!draft) {
return;
}
Object.assign(draft, {
status,
started_at,
updated_at,
error,
completed_at,
created_at,
});
})
);
// Invalidate caches for things we cannot update // Invalidate caches for things we cannot update
// TODO: technically, we could possibly update the current session queue item, but feels safer to just request it again // TODO: technically, we could possibly update the current session queue item, but feels safer to just request it again
dispatch( dispatch(
queueApi.util.invalidateTags(['CurrentSessionQueueItem', 'NextSessionQueueItem', 'InvocationCacheStatus']) queueApi.util.invalidateTags([
'CurrentSessionQueueItem',
'NextSessionQueueItem',
'InvocationCacheStatus',
{ type: 'SessionQueueItem', id: item_id },
])
); );
if (['in_progress'].includes(action.payload.data.status)) { if (['in_progress'].includes(action.payload.data.status)) {