Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] prevent calls to store.query leaking #4042

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions addon/-private/system/record-array-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,22 @@ export default Ember.Object.extend({
var typeClass = array.type;

// unregister filtered record array
var recordArrays = this.filteredRecordArrays.get(typeClass);
var index = recordArrays.indexOf(array);
if (index !== -1) {
recordArrays.splice(index, 1);

// unregister live record array
} else if (this.liveRecordArrays.has(typeClass)) {
var liveRecordArrayForType = this.liveRecordArrayFor(typeClass);
if (array === liveRecordArrayForType) {
this.liveRecordArrays.delete(typeClass);
const recordArrays = this.filteredRecordArrays.get(typeClass);
const removedFromFiltered = remove(recordArrays, array);

// remove from adapter populated record array
const removedFromAdapterPopulated = remove(this._adapterPopulatedRecordArrays, array);

if (!removedFromFiltered && !removedFromAdapterPopulated) {

// unregister live record array
if (this.liveRecordArrays.has(typeClass)) {
var liveRecordArrayForType = this.liveRecordArrayFor(typeClass);
if (array === liveRecordArrayForType) {
this.liveRecordArrays.delete(typeClass);
}
}

}
},

Expand All @@ -316,3 +321,14 @@ function flatten(list) {

return result;
}

function remove(array, item) {
const index = array.indexOf(item);

if (index !== -1) {
array.splice(index, 1);
return true;
}

return false;
}
24 changes: 24 additions & 0 deletions tests/integration/record-array-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,27 @@ test("Should not filter a store.peekAll() array when a record property is change
assert.equal(updateFilterRecordArray.called.length, 0);

});

test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their managers instead of retained when #destroy is called', function(assert) {
run(() => {
store.push({
data: {
type: 'car',
id: '1',
attributes: {
make: 'Honda',
model: 'fit'
}
}
});
});
const query = {};

var adapterPopulated = manager.createAdapterPopulatedRecordArray(Car, query);

run(() => {
adapterPopulated.destroy();
});

assert.equal(manager._adapterPopulatedRecordArrays.length, 0);
});