From a9c299716f07f85083cc86cac24ea9239d38bdef Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 6 Sep 2021 16:23:09 +0400 Subject: [PATCH] Core Data: Adds 'include' to the query key --- .../core-data/src/queried-data/get-query-parts.js | 15 +++++++++------ .../src/queried-data/test/get-query-parts.js | 2 +- .../core-data/src/queried-data/test/selectors.js | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core-data/src/queried-data/get-query-parts.js b/packages/core-data/src/queried-data/get-query-parts.js index 1cd9631495505..9075adb71fabf 100644 --- a/packages/core-data/src/queried-data/get-query-parts.js +++ b/packages/core-data/src/queried-data/get-query-parts.js @@ -60,12 +60,6 @@ export function getQueryParts( query ) { parts.perPage = Number( value ); break; - case 'include': - parts.include = getNormalizedCommaSeparable( value ).map( - Number - ); - break; - case 'context': parts.context = value; break; @@ -82,6 +76,15 @@ export function getQueryParts( query ) { value = parts.fields.join(); } + // Two requests with different include values cannot have same results. + if ( key === 'include' ) { + parts.include = getNormalizedCommaSeparable( value ).map( + Number + ); + // Normalize value for `stableKey`. + value = parts.include.join(); + } + // While it could be any deterministic string, for simplicity's // sake mimic querystring encoding for stable key. // diff --git a/packages/core-data/src/queried-data/test/get-query-parts.js b/packages/core-data/src/queried-data/test/get-query-parts.js index 0de6036d696b3..b3ca692ad09f5 100644 --- a/packages/core-data/src/queried-data/test/get-query-parts.js +++ b/packages/core-data/src/queried-data/test/get-query-parts.js @@ -24,7 +24,7 @@ describe( 'getQueryParts', () => { context: 'default', page: 1, perPage: 10, - stableKey: '', + stableKey: 'include=1', fields: null, include: [ 1 ], } ); diff --git a/packages/core-data/src/queried-data/test/selectors.js b/packages/core-data/src/queried-data/test/selectors.js index 39b46a97a9395..f0a38aab2887e 100644 --- a/packages/core-data/src/queried-data/test/selectors.js +++ b/packages/core-data/src/queried-data/test/selectors.js @@ -82,6 +82,7 @@ describe( 'getQueriedItems', () => { queries: { default: { '': [ 1, 2 ], + 'include=1': [ 1 ], }, }, };