Commit 07a8b271 authored by Jose Vargas's avatar Jose Vargas Committed by Jose Ivan Vargas

Changes the cache config and the specs

This allows for the cache to update if the incoming
elements are different to the existing cache
parent 19408e9d
import { isEqual } from 'lodash';
import { isEqual, differenceWith } from 'lodash';
export default {
typePolicies: {
......@@ -14,7 +14,16 @@ export default {
let nodes;
if (Object.keys(existing).length !== 0 && isEqual(existing?.statuses, args?.statuses)) {
nodes = [...existing.nodes, ...incoming.nodes];
const diff = differenceWith(existing.nodes, incoming.nodes, isEqual);
if (existing.nodes.length === incoming.nodes.length) {
if (diff.length !== 0) {
nodes = [...existing.nodes, ...diff];
} else {
nodes = [...existing.nodes];
}
} else {
nodes = [...existing.nodes, ...incoming.nodes];
}
} else {
nodes = [...incoming.nodes];
}
......
......@@ -33,6 +33,18 @@ describe('jobs/components/table/graphql/cache_config', () => {
);
});
it('should not add to existing cache if the incoming elements are the same', () => {
const res = cacheConfig.typePolicies.CiJobConnection.merge(
CIJobConnectionExistingCache,
CIJobConnectionExistingCache,
{
args: firstLoadArgs,
},
);
expect(res.nodes).toHaveLength(CIJobConnectionExistingCache.nodes.length);
});
it('should contain the pageInfo key as part of the result', () => {
const res = cacheConfig.typePolicies.CiJobConnection.merge({}, CIJobConnectionIncomingCache, {
args: firstLoadArgs,
......
......@@ -1912,9 +1912,9 @@ export const CIJobConnectionIncomingCacheRunningStatus = {
export const CIJobConnectionExistingCache = {
nodes: [
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2057' },
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2056' },
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2051' },
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2100' },
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2101' },
{ __ref: 'CiJob:gid://gitlab/Ci::Build/2102' },
],
statuses: 'PENDING',
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment