refactor: generalize ActionCable cache invalidation over the model registry
Replaces the three hardcoded dispatches in actionCable.onCacheInvalidate and ReconnectService.revalidateCaches with a loop over cacheableModels. Adding a new cached model no longer requires editing these two handlers — they pick it up automatically from the registry. Also guards against partial server payloads: dispatches are skipped for models whose key is undefined, so a client running ahead of a server deploy keeps working without spurious dispatches.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
isAInboxViewRoute,
|
||||
isNotificationRoute,
|
||||
} from 'dashboard/helper/routeHelpers';
|
||||
import { cacheableModels } from 'dashboard/helper/CacheHelper/cacheableModels';
|
||||
|
||||
const MAX_DISCONNECT_SECONDS = 10800;
|
||||
|
||||
@@ -99,14 +100,14 @@ class ReconnectService {
|
||||
};
|
||||
|
||||
revalidateCaches = async () => {
|
||||
const { label, inbox, team } = await this.store.dispatch(
|
||||
'accounts/getCacheKeys'
|
||||
const keys = (await this.store.dispatch('accounts/getCacheKeys')) || {};
|
||||
await Promise.all(
|
||||
cacheableModels
|
||||
.filter(model => keys[model.name] !== undefined)
|
||||
.map(model =>
|
||||
this.store.dispatch(model.dispatchPath, { newKey: keys[model.name] })
|
||||
)
|
||||
);
|
||||
await Promise.all([
|
||||
this.store.dispatch('labels/revalidate', { newKey: label }),
|
||||
this.store.dispatch('inboxes/revalidate', { newKey: inbox }),
|
||||
this.store.dispatch('teams/revalidate', { newKey: team }),
|
||||
]);
|
||||
};
|
||||
|
||||
handleRouteSpecificFetch = async () => {
|
||||
|
||||
Reference in New Issue
Block a user