Skip to content
Snippets Groups Projects
Commit bb4496fb authored by Denys Rul's avatar Denys Rul
Browse files

MAGETWO-59322: Incorrect scope filter caching in UI grids

- Drop cache when certain request parameters change
parent 5ffafe22
No related merge requests found
......@@ -23,6 +23,9 @@
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="dataNamespace" xsi:type="string">filters.store_id</item>
</item>
</item>
</argument>
</argument>
......
......@@ -20,6 +20,7 @@ define([
method: 'GET',
dataType: 'json'
},
dataNamespace: '',
data: {}
},
......@@ -29,8 +30,16 @@ define([
* @returns {DataStorage} Chainable.
*/
initConfig: function () {
var namespace;
this._super();
namespace = this.dataNamespace;
if (typeof namespace === 'string') {
this.dataNamespace = namespace ? [namespace] : [];
}
this._requests = [];
return this;
......@@ -77,10 +86,12 @@ define([
* @returns {jQueryPromise}
*/
getData: function (params, options) {
var cachedRequest = this.getRequest(params);
var cachedRequest;
if (params && params.filters && params.filters['store_id']) {
cachedRequest = false;
if (this.hasNamespaceChanged(params)) {
this.clearRequests();
} else {
cachedRequest = this.getRequest(params);
}
options = options || {};
......@@ -90,6 +101,28 @@ define([
this.requestData(params);
},
/**
* Tells whether one of the parameters defined in the "dataNamespace" has
* changed since the last request.
*
* @param {Object} params - Request parameters.
* @returns {Boolean}
*/
hasNamespaceChanged: function (params) {
var lastRequest = _.last(this._requests),
paths,
diff;
if (!lastRequest) {
return false;
}
diff = utils.compare(lastRequest.params, params);
paths = _.pluck(diff.changes, 'path').concat(_.keys(diff.containers));
return _.intersection(this.dataNamespace, paths).length > 0;
},
/**
* Extends records of current data object
* with the provided records collection.
......
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