diff --git a/app/adapters/crate.js b/app/adapters/crate.js index 9328d6cc674..544514604bf 100644 --- a/app/adapters/crate.js +++ b/app/adapters/crate.js @@ -5,6 +5,15 @@ const BULK_REQUEST_GROUP_SIZE = 10; export default class CrateAdapter extends ApplicationAdapter { coalesceFindRequests = true; + findRecord(store, type, id, snapshot) { + let { include } = snapshot; + // This ensures `crate.versions` are always fetched from another request. + if (include === undefined) { + snapshot.include = 'keywords,categories,downloads'; + } + return super.findRecord(store, type, id, snapshot); + } + groupRecordsForFindMany(store, snapshots) { let result = []; for (let i = 0; i < snapshots.length; i += BULK_REQUEST_GROUP_SIZE) { diff --git a/e2e/acceptance/crate-dependencies.spec.ts b/e2e/acceptance/crate-dependencies.spec.ts index aa126869b8f..451412c9e91 100644 --- a/e2e/acceptance/crate-dependencies.spec.ts +++ b/e2e/acceptance/crate-dependencies.spec.ts @@ -76,16 +76,17 @@ test.describe('Acceptance | crate dependencies page', { tag: '@acceptance' }, () }); await ember.addHook(async owner => { - // Load `crate` and then explicitly unload the side-loaded `versions`. + // Load `crate` and ensure all `versions` are not loaded. let store = owner.lookup('service:store'); let crateRecord = await store.findRecord('crate', 'foo'); - let versions = crateRecord.hasMany('versions').value(); - versions.forEach(record => record.unloadRecord()); + let versionsRef = crateRecord.hasMany('versions'); + globalThis.version_ids = versionsRef.ids(); }); await page.goto('/crates/foo/1.0.0/dependencies'); await expect(page).toHaveURL('/crates/foo/1.0.0/dependencies'); + await page.waitForFunction(() => globalThis.version_ids?.length === 0); await expect(page.locator('[data-test-404-page]')).toBeVisible(); await expect(page.locator('[data-test-title]')).toHaveText('foo: Failed to load version data'); await expect(page.locator('[data-test-go-back]')).toHaveCount(0); diff --git a/e2e/routes/crate/range.spec.ts b/e2e/routes/crate/range.spec.ts index 3d760404f46..b6ba6744858 100644 --- a/e2e/routes/crate/range.spec.ts +++ b/e2e/routes/crate/range.spec.ts @@ -128,15 +128,16 @@ test.describe('Route | crate.range', { tag: '@routes' }, () => { }); await ember.addHook(async owner => { - // Load `crate` and then explicitly unload the side-loaded `versions`. + // Load `crate` and ensure all `versions` are not loaded. let store = owner.lookup('service:store'); let crateRecord = await store.findRecord('crate', 'foo'); - let versions = crateRecord.hasMany('versions').value(); - versions.forEach(record => record.unloadRecord()); + let versionsRef = crateRecord.hasMany('versions'); + globalThis.version_ids = versionsRef.ids(); }); await page.goto('/crates/foo/range/^3'); await expect(page).toHaveURL('/crates/foo/range/%5E3'); + await page.waitForFunction(() => globalThis.version_ids?.length === 0); await expect(page.locator('[data-test-404-page]')).toBeVisible(); await expect(page.locator('[data-test-title]')).toHaveText('foo: Failed to load version data'); await expect(page.locator('[data-test-go-back]')).toHaveCount(0); diff --git a/tests/acceptance/crate-dependencies-test.js b/tests/acceptance/crate-dependencies-test.js index 0abe94438b9..17e6a7612f7 100644 --- a/tests/acceptance/crate-dependencies-test.js +++ b/tests/acceptance/crate-dependencies-test.js @@ -78,11 +78,11 @@ module('Acceptance | crate dependencies page', function (hooks) { this.server.get('/api/v1/crates/:crate_name/versions', {}, 500); - // Load `crate` and then explicitly unload the side-loaded `versions`. + // Load `crate` and ensure all `versions` are not loaded. let store = this.owner.lookup('service:store'); let crateRecord = await store.findRecord('crate', 'foo'); - let versions = crateRecord.hasMany('versions').value(); - versions.forEach(record => record.unloadRecord()); + let versionsRef = crateRecord.hasMany('versions'); + assert.deepEqual(versionsRef.ids(), []); await visit('/crates/foo/1.0.0/dependencies'); assert.strictEqual(currentURL(), '/crates/foo/1.0.0/dependencies'); diff --git a/tests/adapters/crate-test.js b/tests/adapters/crate-test.js index 0b4a6722f27..2dcf265ce20 100644 --- a/tests/adapters/crate-test.js +++ b/tests/adapters/crate-test.js @@ -22,4 +22,21 @@ module('Adapter | crate', function (hooks) { assert.strictEqual(foo?.name, 'foo'); assert.strictEqual(bar?.name, 'bar'); }); + + test('findRecord requests do not include versions by default', async function (assert) { + let _foo = this.server.create('crate', { name: 'foo' }); + let version = this.server.create('version', { crate: _foo }); + + let store = this.owner.lookup('service:store'); + + let foo = await store.findRecord('crate', 'foo'); + assert.strictEqual(foo?.name, 'foo'); + + // versions should not be loaded yet + let versionsRef = foo.hasMany('versions'); + assert.deepEqual(versionsRef.ids(), []); + + await versionsRef.load(); + assert.deepEqual(versionsRef.ids(), [version.id]); + }); }); diff --git a/tests/models/version-test.js b/tests/models/version-test.js index 92203fc2e2c..fb92b98ff6f 100644 --- a/tests/models/version-test.js +++ b/tests/models/version-test.js @@ -229,7 +229,7 @@ module('Model | Version', function (hooks) { this.server.create('version', { crate, num: '0.4.2' }); this.server.create('version', { crate, num: '0.4.3', yanked: true }); crateRecord = await this.store.findRecord('crate', crate.name, { reload: true }); - versions = (await crateRecord.loadVersionsTask.perform()).slice(); + versions = (await crateRecord.loadVersionsTask.perform({ reload: true })).slice(); assert.deepEqual( versions.map(it => ({ num: it.num, isHighestOfReleaseTrack: it.isHighestOfReleaseTrack })), diff --git a/tests/routes/crate/range-test.js b/tests/routes/crate/range-test.js index 61474b7ad07..7ccb265136e 100644 --- a/tests/routes/crate/range-test.js +++ b/tests/routes/crate/range-test.js @@ -119,11 +119,11 @@ module('Route | crate.range', function (hooks) { this.server.get('/api/v1/crates/:crate_name/versions', {}, 500); - // Load `crate` and then explicitly unload the side-loaded `versions`. + // Load `crate` and ensure all `versions` are not loaded. let store = this.owner.lookup('service:store'); let crateRecord = await store.findRecord('crate', 'foo'); - let versions = crateRecord.hasMany('versions').value(); - versions.forEach(record => record.unloadRecord()); + let versionsRef = crateRecord.hasMany('versions'); + assert.deepEqual(versionsRef.ids(), []); await visit('/crates/foo/range/^3'); assert.strictEqual(currentURL(), '/crates/foo/range/%5E3');