Skip to content

Commit

Permalink
[BUGFIX beta] Remove non-functional (error prone) manual CP caching.
Browse files Browse the repository at this point in the history
The previous implementation was intending to cache relationships when in
the production environment, but avoid caching them in development.
Unfortunately, this code was factored in a way that relied on mutating
internal private state of the underlying `Ember.ComputedProperty`
instance when `Ember.testing` was true (which was used as a way to
determine prod vs non-prod).

When this code was introduced (2014-12-02), setting `_cacheable` on a
`ComputedProperty` instance would have worked as intended, however a
refactor in Ember (ironically one day prior, but on Ember's canary
channel) deprecated using `_cacheable` or `.cacheable()` (in favor of
opting out of caching via `.volatile()`).

Since this has not worked since Ember 2.0.0, and it has not been an
issue, this commit completely removes the manual caching / volatile
swapping between prod/dev/testing environments.
  • Loading branch information
rwjblue committed Jan 22, 2018
1 parent 7d0174e commit 27fcef2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
9 changes: 0 additions & 9 deletions addon/-private/system/relationships/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import { A } from '@ember/array';
import { computed } from '@ember/object';
import MapWithDefault from '@ember/map/with-default';
import Map from '@ember/map';
import Ember from 'ember';
import { assert } from '@ember/debug';
import {
typeForRelationshipMeta,
relationshipFromMeta
} from "../relationship-meta";

export const relationshipsDescriptor = computed(function() {
if (Ember.testing === true && relationshipsDescriptor._cacheable === true) {
relationshipsDescriptor._cacheable = false;
}

let map = new MapWithDefault({
defaultValue() { return []; }
});
Expand All @@ -37,10 +32,6 @@ export const relationshipsDescriptor = computed(function() {
}).readOnly();

export const relatedTypesDescriptor = computed(function() {
if (Ember.testing === true && relatedTypesDescriptor._cacheable === true) {
relatedTypesDescriptor._cacheable = false;
}

let modelName;
let types = A();

Expand Down
72 changes: 0 additions & 72 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,78 +542,6 @@ test("relationshipsByName does not cache a factory", function(assert) {
"model factory based on relationship type matches the model based on store.modelFor");
});

function getDescriptor(object, key) {
var meta = Ember.meta(object);
var mixins = (meta && meta._mixins) || {};
for (let key in mixins) {
let klass = mixins[key]
if (!klass.properties) {
continue;
}
let descriptor = klass.properties[key];
if (descriptor) {
return descriptor;
}
}
// Fallback to grabbing the descriptor off of the object for old
// versions of Ember
return object[key];
}

test("relationshipsByName is cached in production", function(assert) {
let model = store.modelFor('user');
let oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
let relationshipsByName = getDescriptor(model, 'relationshipsByName');
let oldCacheable = relationshipsByName._cacheable;
relationshipsByName._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
assert.equal(get(model, 'relationshipsByName'), get(model, 'relationshipsByName'), 'relationshipsByName are cached');
} finally {
Ember.testing = oldTesting;
relationshipsByName._cacheable = oldCacheable;
}
});

test("relatedTypes is cached in production", function(assert) {
let model = store.modelFor('user');
let oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
let relatedTypes = getDescriptor(model, 'relatedTypes');
let oldCacheable = relatedTypes._cacheable;
relatedTypes._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
assert.equal(get(model, 'relatedTypes'), get(model, 'relatedTypes'), 'relatedTypes are cached');
} finally {
Ember.testing = oldTesting;
relatedTypes._cacheable = oldCacheable;
}
});

test("relationships is cached in production", function(assert) {
let model = store.modelFor('user');
let oldTesting = Ember.testing;
//We set the cacheable to true because that is the default state for any CP and then assert that it
//did not get dynamically changed when accessed
let relationships = getDescriptor(model, 'relationships');
let oldCacheable = relationships._cacheable;
relationships._cacheable = true;
Ember.testing = false;
try {
assert.equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
assert.equal(get(model, 'relationships'), get(model, 'relationships'), 'relationships are cached');
} finally {
Ember.testing = oldTesting;
relationships._cacheable = oldCacheable;
}
});

test("relationship changes shouldn’t cause async fetches", function(assert) {
assert.expect(2);

Expand Down

0 comments on commit 27fcef2

Please sign in to comment.