-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/unpublished-relationship-performance-test-app/app/models/child.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import DS from 'ember-data'; | ||
|
||
const { Model, attr, belongsTo, hasMany } = DS; | ||
|
||
export default Model.extend({ | ||
childName: attr('string'), | ||
friends: hasMany('child', { async: true }), | ||
bestFriend: belongsTo('child', { async: true }), | ||
secondBestFriend: belongsTo('child', { async: true }), | ||
parent: belongsTo('parent', { async: true }), | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/unpublished-relationship-performance-test-app/app/models/parent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import DS from 'ember-data'; | ||
|
||
const { Model, attr, hasMany } = DS; | ||
|
||
export default Model.extend({ | ||
parentName: attr('string'), | ||
children: hasMany('child', { async: true }), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/unpublished-relationship-performance-test-app/app/routes/add-children.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
import { createParentPayload } from '../utils/create-parent-payload'; | ||
import { endTrace } from '../utils/end-trace'; | ||
|
||
export default Route.extend({ | ||
model() { | ||
performance.mark('start-data-generation'); | ||
|
||
const initialPayload = createParentPayload(19600); | ||
const updatePayload = createParentPayload(20000); | ||
|
||
performance.mark('end-data-generation'); | ||
performance.measure('data-generation', 'start-data-generation', 'end-data-generation'); | ||
|
||
performance.mark('start-push-initial-payload'); | ||
this.store.push(initialPayload); | ||
performance.mark('end-push-initial-payload'); | ||
performance.measure('push-initial-payload', 'start-push-initial-payload', 'end-push-initial-payload'); | ||
|
||
performance.mark('start-push-update-payload'); | ||
this.store.push(updatePayload); | ||
performance.mark('end-push-update-payload'); | ||
performance.measure('push-update-payload', 'start-push-update-payload', 'end-push-update-payload'); | ||
}, | ||
|
||
afterModel() { | ||
endTrace(); | ||
}, | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/unpublished-relationship-performance-test-app/app/routes/destroy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Route from '@ember/routing/route'; | ||
import { schedule } from '@ember/runloop'; | ||
|
||
import { all, Promise } from 'rsvp'; | ||
|
||
import { createParentPayload } from '../utils/create-parent-payload'; | ||
import { endTrace } from '../utils/end-trace'; | ||
|
||
export default Route.extend({ | ||
model() { | ||
performance.mark('start-data-generation'); | ||
|
||
const payload = createParentPayload(2000, 500); | ||
|
||
performance.mark('end-data-generation'); | ||
performance.measure('data-generation', 'start-data-generation', 'end-data-generation'); | ||
|
||
performance.mark('start-push-payload'); | ||
const result = this.store.push(payload); | ||
performance.mark('end-push-payload'); | ||
performance.measure('push-payload', 'start-push-payload', 'end-push-payload'); | ||
|
||
performance.mark('start-destroyRecord'); | ||
const parent = result[0]; | ||
const childrenPromise = all( | ||
parent | ||
.get('children') | ||
.toArray() | ||
.map(child => child.destroyRecord().then(() => child.unloadRecord())) | ||
); | ||
const parentPromise = parent.destroyRecord().then(() => parent.unloadRecord()); | ||
|
||
return all([childrenPromise, parentPromise]).then( | ||
() => | ||
new Promise((resolve, reject) => { | ||
schedule('destroy', this, () => { | ||
performance.mark('end-destroyRecord'); | ||
performance.measure('destroyRecord', 'start-destroyRecord', 'end-destroyRecord'); | ||
resolve(); | ||
}); | ||
}) | ||
); | ||
}, | ||
|
||
afterModel() { | ||
endTrace(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/unpublished-relationship-performance-test-app/app/routes/unload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Route from '@ember/routing/route'; | ||
import { schedule } from '@ember/runloop'; | ||
|
||
import { Promise } from 'rsvp'; | ||
|
||
import { createParentPayload } from '../utils/create-parent-payload'; | ||
import { endTrace } from '../utils/end-trace'; | ||
|
||
export default Route.extend({ | ||
model() { | ||
performance.mark('start-data-generation'); | ||
|
||
const payload = createParentPayload(2000, 500); | ||
|
||
performance.mark('end-data-generation'); | ||
performance.measure('data-generation', 'start-data-generation', 'end-data-generation'); | ||
|
||
performance.mark('start-push-payload'); | ||
const result = this.store.push(payload); | ||
performance.mark('end-push-payload'); | ||
performance.measure('push-payload', 'start-push-payload', 'end-push-payload'); | ||
|
||
performance.mark('start-unloadRecord'); | ||
const parent = result[0]; | ||
parent | ||
.get('children') | ||
.toArray() | ||
.forEach(child => child.unloadRecord()); | ||
parent.unloadRecord(); | ||
|
||
return new Promise((resolve, reject) => { | ||
schedule('destroy', this, () => { | ||
performance.mark('end-unloadRecord'); | ||
performance.measure('unloadRecord', 'start-unloadRecord', 'end-unloadRecord'); | ||
resolve(); | ||
}); | ||
}); | ||
}, | ||
|
||
afterModel() { | ||
endTrace(); | ||
}, | ||
}); |
74 changes: 74 additions & 0 deletions
74
packages/unpublished-relationship-performance-test-app/app/utils/create-parent-payload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Creates a `parent` with `nrChildren` children and each `child` has `nrFriends` friends. | ||
* If `nrFriends > 0` then each child also has a `bestFriend` and a `secondBestFriend`. | ||
*/ | ||
export function createParentPayload(nrChildren, nrFriends) { | ||
const parentId = '1'; | ||
const payload = { | ||
data: [ | ||
{ | ||
id: parentId, | ||
type: 'parent', | ||
attributes: { | ||
parentName: 'parent name', | ||
}, | ||
relationships: { | ||
children: { | ||
data: [], | ||
}, | ||
}, | ||
}, | ||
], | ||
included: [], | ||
}; | ||
const childrenRel = payload.data[0].relationships.children.data; | ||
const included = payload.included; | ||
|
||
for (let i = 0; i < nrChildren; i++) { | ||
const childId = `${parentId}-${i}`; | ||
let child = { | ||
id: childId, | ||
type: 'child', | ||
}; | ||
childrenRel.push(child); | ||
|
||
child = Object.assign({}, child, { | ||
attributes: { | ||
childName: `child-${childId}`, | ||
}, | ||
}); | ||
included.push(child); | ||
|
||
if (nrFriends > 0) { | ||
Object.assign(child, { | ||
relationships: { | ||
friends: { | ||
data: [], | ||
}, | ||
bestFriend: { | ||
data: { | ||
id: `${parentId}-${(i + 1) % nrChildren}`, | ||
type: 'child', | ||
}, | ||
}, | ||
secondBestFriend: { | ||
data: { | ||
id: `${parentId}-${(i + 2) % nrChildren}`, | ||
type: 'child', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const friendsRel = child.relationships.friends.data; | ||
for (let j = 0; j < nrFriends; j++) { | ||
friendsRel.push({ | ||
id: `${parentId}-${(i + 1) % nrChildren}`, | ||
type: 'child', | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return payload; | ||
} |