From 27fcef2499346d1ca32868d394d9f6b48693f3db Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 22 Jan 2018 13:32:47 -0500 Subject: [PATCH] [BUGFIX beta] Remove non-functional (error prone) manual CP caching. 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. --- addon/-private/system/relationships/ext.js | 9 --- .../relationships/belongs-to-test.js | 72 ------------------- 2 files changed, 81 deletions(-) diff --git a/addon/-private/system/relationships/ext.js b/addon/-private/system/relationships/ext.js index 872d9f0e1f2..2a8bf05159e 100644 --- a/addon/-private/system/relationships/ext.js +++ b/addon/-private/system/relationships/ext.js @@ -2,7 +2,6 @@ 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, @@ -10,10 +9,6 @@ import { } from "../relationship-meta"; export const relationshipsDescriptor = computed(function() { - if (Ember.testing === true && relationshipsDescriptor._cacheable === true) { - relationshipsDescriptor._cacheable = false; - } - let map = new MapWithDefault({ defaultValue() { return []; } }); @@ -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(); diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 842aff95feb..f159f4f9002 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -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);