Skip to content

Commit bb4496f

Browse files
author
Denys Rul
committed
MAGETWO-59322: Incorrect scope filter caching in UI grids
- Drop cache when certain request parameters change
1 parent 5ffafe2 commit bb4496f

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

app/code/Magento/Catalog/view/adminhtml/ui_component/product_listing.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<item name="config" xsi:type="array">
2424
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
2525
<item name="update_url" xsi:type="url" path="mui/index/render"/>
26+
<item name="storageConfig" xsi:type="array">
27+
<item name="dataNamespace" xsi:type="string">filters.store_id</item>
28+
</item>
2629
</item>
2730
</argument>
2831
</argument>

app/code/Magento/Ui/view/base/web/js/grid/data-storage.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ define([
2020
method: 'GET',
2121
dataType: 'json'
2222
},
23+
dataNamespace: '',
2324
data: {}
2425
},
2526

@@ -29,8 +30,16 @@ define([
2930
* @returns {DataStorage} Chainable.
3031
*/
3132
initConfig: function () {
33+
var namespace;
34+
3235
this._super();
3336

37+
namespace = this.dataNamespace;
38+
39+
if (typeof namespace === 'string') {
40+
this.dataNamespace = namespace ? [namespace] : [];
41+
}
42+
3443
this._requests = [];
3544

3645
return this;
@@ -77,10 +86,12 @@ define([
7786
* @returns {jQueryPromise}
7887
*/
7988
getData: function (params, options) {
80-
var cachedRequest = this.getRequest(params);
89+
var cachedRequest;
8190

82-
if (params && params.filters && params.filters['store_id']) {
83-
cachedRequest = false;
91+
if (this.hasNamespaceChanged(params)) {
92+
this.clearRequests();
93+
} else {
94+
cachedRequest = this.getRequest(params);
8495
}
8596

8697
options = options || {};
@@ -90,6 +101,28 @@ define([
90101
this.requestData(params);
91102
},
92103

104+
/**
105+
* Tells whether one of the parameters defined in the "dataNamespace" has
106+
* changed since the last request.
107+
*
108+
* @param {Object} params - Request parameters.
109+
* @returns {Boolean}
110+
*/
111+
hasNamespaceChanged: function (params) {
112+
var lastRequest = _.last(this._requests),
113+
paths,
114+
diff;
115+
116+
if (!lastRequest) {
117+
return false;
118+
}
119+
120+
diff = utils.compare(lastRequest.params, params);
121+
paths = _.pluck(diff.changes, 'path').concat(_.keys(diff.containers));
122+
123+
return _.intersection(this.dataNamespace, paths).length > 0;
124+
},
125+
93126
/**
94127
* Extends records of current data object
95128
* with the provided records collection.

0 commit comments

Comments
 (0)