Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mauritslamers/78d0963e08c5e128363e to your computer and use it in GitHub Desktop.
Save mauritslamers/78d0963e08c5e128363e to your computer and use it in GitHub Desktop.
// Init
App = SC.Application.create({
store: SC.Store.create().from(SC.Record.fixtures)
});
App.Contact = SC.Record.extend({
firstName: SC.Record.attr(String, { key: 'first_name' }),
lastName: SC.Record.attr(String, { key: 'last_name' }),
age: SC.Record.attr(Number),
ageSlow: function() {
function slow(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
};
slow(5); //busy wait 5ms
return this.get('age');
}.property('age').cacheable(),
});
SC.run(function () {
var i = 0;
for (i= 0; i < 1000; i++) {
App.store.createRecord(App.Contact, { firstName: 'Florian'+i, lastName: 'Kugler'+i, age: i}, i);
}
});
var ra;
// Test where we have the time to perform Query on 1 run loop
SC.run(function () {
ra = App.store.find(SC.Query.local(App.Contact, {
conditions: 'age > 100'
}));
ra.addProbe('status');
console.trace("RecordArray is in ReadClean state: " + (ra.get('status') & SC.Record.READY_CLEAN));
array = ra.toArray();
console.trace("Array length (expected 899): "+ array.length);
console.trace('record array length (expected 899): ' + ra.get('length'));
});
var ra2;
// Test where we don't have the time to retrieve all data
// call it multiple time if needed
SC.run(function () {
ra2 = App.store.find(SC.Query.local(App.Contact, {
conditions: 'ageSlow > 100'
}));
console.trace("RecordArray is in ReadClean state: " + (ra2.get('status') & SC.Record.READY_CLEAN));
var array = ra2.toArray();
console.trace("Array length (expected 899): "+ array.length);
console.trace('record array length (expected 899): ' + ra2.get('length'));
console.trace('record array length of storekeys: ' + ra2.getPath('storeKeys.length'));
var numloops = 0;
ra2.addProbe('status');
ra2.invokeNext(function ranext () {
var l = ra2.get('length');
if (l < 898) {
numloops += 1;
ra2.invokeNext(ranext);
}
else {
console.log("on runloop " + numloops + " length is " + ra2.get('length'));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment