-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathadd-children-to-materialized.js
52 lines (41 loc) · 1.64 KB
/
add-children-to-materialized.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Route from '@ember/routing/route';
import { service } from '@ember/service';
export default Route.extend({
store: service(),
async model() {
performance.mark('start-data-generation');
const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json());
const updatePayload = await fetch('./fixtures/add-children-final.json').then((r) => r.json());
performance.mark('start-push-initial-payload');
this.store.push(initialPayload);
performance.mark('start-initial-materialize-records');
let peekedParents = this.store.peekAll('parent').slice();
this.store.peekAll('child').slice();
performance.mark('start-initial-materialize-relationships');
let seen = new Set();
peekedParents.forEach((parent) => iterateParent(parent, seen));
performance.mark('start-push-update-payload');
this.store.push(updatePayload);
performance.mark('start-materialize-all-records');
peekedParents = this.store.peekAll('parent').slice();
this.store.peekAll('child').slice();
performance.mark('start-materialize-all-relationships');
seen = new Set();
peekedParents.forEach((parent) => iterateParent(parent, seen));
performance.mark('end-materialize-all-relationships');
},
});
function iterateChild(record, seen) {
if (seen.has(record)) {
return;
}
seen.add(record);
// record.parent.get('name');
record.bestFriend.get('name');
record.secondBestFriend.get('name');
record.friends.forEach((child) => iterateChild(child, seen));
}
function iterateParent(record, seen) {
seen.add(record);
record.children.forEach((child) => iterateChild(child, seen));
}