refactor: deduplicate cache revalidation actions

This commit is contained in:
Shivam Mishra
2026-06-08 18:39:40 +05:30
parent 0deb026f9d
commit 625302ac3c
8 changed files with 129 additions and 71 deletions
@@ -2,6 +2,7 @@ import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
import types from '../mutation-types';
import AttributeAPI from '../../api/attributes';
import camelcaseKeys from 'camelcase-keys';
import { createCacheRevalidateAction } from '../utils/cacheRevalidate';
export const state = {
records: [],
@@ -54,17 +55,10 @@ export const actions = {
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: false });
}
},
revalidate: async ({ commit }, { newKey }) => {
try {
const isExistingKeyValid = await AttributeAPI.validateCacheKey(newKey);
if (!isExistingKeyValid) {
const response = await AttributeAPI.refetchAndCommit(newKey);
commit(types.SET_CUSTOM_ATTRIBUTE, response.data);
}
} catch (error) {
// Ignore error
}
},
revalidate: createCacheRevalidateAction({
api: AttributeAPI,
mutation: types.SET_CUSTOM_ATTRIBUTE,
}),
create: async function createAttribute({ commit }, attributeObj) {
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isCreating: true });
try {