Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1136170 - [Messages] Adjust the read ahead number to be the same …
Browse files Browse the repository at this point in the history
…or higher than what the max number of threads on Flame r=azasypkin, schung
  • Loading branch information
julienw authored and rvandermeulen committed Mar 13, 2015
1 parent 5777932 commit 6a750c9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
12 changes: 12 additions & 0 deletions apps/sms/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var Settings = {
smsServiceId: 'ril.sms.defaultServiceId'
},

READ_AHEAD_THREADS_KEY: 'ril.sms.maxReadAheadEntries',

// we evaluate to 5KB the size overhead of wrapping a payload in a MMS
MMS_SIZE_OVERHEAD: 5 * 1024,

Expand Down Expand Up @@ -194,5 +196,15 @@ var Settings = {

var conn = navigator.mozMobileConnections[index];
return MobileOperator.userFacingInfo(conn).operator;
},

setReadAheadThreadRetrieval: function(value) {
if (!navigator.mozSettings) {
return;
}

var setting = {};
setting[this.READ_AHEAD_THREADS_KEY] = value;
navigator.mozSettings.createLock().set(setting);
}
};
17 changes: 15 additions & 2 deletions apps/sms/js/thread_list_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
PerformanceTestingHelper, StickyHeader, Navigation,
InterInstanceEventDispatcher,
SelectionHandler,
Settings,
LazyLoader
*/
/*exported ThreadListUI */
Expand All @@ -25,6 +26,7 @@ var ThreadListUI = {
draftLinks: null,
draftRegistry: null,
DRAFT_SAVED_DURATION: 5000,
FIRST_PANEL_THREAD_COUNT: 9, // counted on a Peak

// Used to track timeouts
timeouts: {
Expand Down Expand Up @@ -545,12 +547,16 @@ var ThreadListUI = {
this.sticky && this.sticky.refresh();
},

ensureReadAheadSetting: function thlui_ensureReadAheadSettting() {
Settings.setReadAheadThreadRetrieval(this.FIRST_PANEL_THREAD_COUNT);
},

renderThreads: function thlui_renderThreads(firstViewDoneCb, allDoneCb) {
window.performance.mark('willRenderThreads');
PerformanceTestingHelper.dispatch('will-render-threads');

var hasThreads = false;
var firstPanelCount = 9; // counted on a Peak
var firstPanelCount = this.FIRST_PANEL_THREAD_COUNT;

this.prepareRendering();

Expand Down Expand Up @@ -605,10 +611,17 @@ var ThreadListUI = {
}
}

function onDone() {
/* jshint validthis: true */

this.ensureReadAheadSetting();
allDoneCb && allDoneCb();
}

var renderingOptions = {
each: onRenderThread.bind(this),
end: onThreadsRendered.bind(this),
done: allDoneCb
done: onDone.bind(this)
};

MessageManager.getThreads(renderingOptions);
Expand Down
1 change: 1 addition & 0 deletions apps/sms/test/unit/mock_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var MockSettings = {
getServiceIdByIccId: function() { return null; },
getSimNameByIccId: function(id) { return 'sim-name-' + id; },
getOperatorByIccId: function(id) { return 'sim-operator-' + id; },
setReadAheadThreadRetrieval: function() {},

mSetup: function() {
MockSettings.mmsSizeLimitation = 295 * 1024;
Expand Down
18 changes: 17 additions & 1 deletion apps/sms/test/unit/settings_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ suite('Settings >', function() {
test('getServiceIdByIccId returns null', function() {
assert.isNull(Settings.getServiceIdByIccId('anything'));
});

test('setReadAheadThreadRetrieval does nothing', function() {
assert.doesNotThrow(() => {
Settings.setReadAheadThreadRetrieval(9);
});
});
});

suite('With mozSettings', function() {
Expand Down Expand Up @@ -141,6 +147,7 @@ suite('Settings >', function() {
set: function() {}
};
sinon.spy(api, 'get');
sinon.spy(api, 'set');
return api;
});
});
Expand Down Expand Up @@ -384,8 +391,17 @@ suite('Settings >', function() {

conn.data.state = 'registered';
listenerSpy.yield();

});
});

test('setReadAheadThreadRetrieval()', function() {
Settings.setReadAheadThreadRetrieval(9);

sinon.assert.calledWithMatch(
navigator.mozSettings.createLock.lastCall.returnValue.set,
{ 'ril.sms.maxReadAheadEntries' : 9 }
);
});
});
});
13 changes: 11 additions & 2 deletions apps/sms/test/unit/thread_list_ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MessageManager, WaitingScreen, Threads, Template, MockMessages,
MockThreadList, MockTimeHeaders, Draft, Drafts, Thread, ThreadUI,
MockOptionMenu, Utils, Contacts, MockContact, Navigation,
MockSettings,
MockSettings, Settings,
InterInstanceEventDispatcher,
MockStickyHeader,
StickyHeader
Expand Down Expand Up @@ -54,7 +54,8 @@ var mocksHelperForThreadListUI = new MocksHelper([
'Navigation',
'InterInstanceEventDispatcher',
'SelectionHandler',
'LazyLoader'
'LazyLoader',
'Settings'
]).init();

suite('thread_list_ui', function() {
Expand Down Expand Up @@ -1212,6 +1213,9 @@ suite('thread_list_ui', function() {
this.sinon.spy(ThreadListUI, 'renderDrafts');
this.sinon.spy(MockStickyHeader.prototype, 'refresh');
this.sinon.spy(window, 'StickyHeader');

this.sinon.stub(Settings, 'setReadAheadThreadRetrieval');

firstViewDone = sinon.stub();

Threads.clear();
Expand Down Expand Up @@ -1290,6 +1294,11 @@ suite('thread_list_ui', function() {
// Check that all threads have been properly inserted in the list
assert.equal(mmsThreads.length, 2);
assert.equal(smsThreads.length, 8);

sinon.assert.calledWith(
Settings.setReadAheadThreadRetrieval,
ThreadListUI.FIRST_PANEL_THREAD_COUNT
);
});
});
});
Expand Down

0 comments on commit 6a750c9

Please sign in to comment.