1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 18:32:20 -05:00

put sentDate in lawnchair key, reducing sort complexity

This commit is contained in:
Tankred Hase 2013-06-03 02:17:20 +02:00
parent ef05addc31
commit 5a2a559485
3 changed files with 11 additions and 22 deletions

View File

@ -27,9 +27,9 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) {
// put date in key if available... for easy querying
if (i.sentDate) {
date = util.parseDate(i.sentDate);
key = crypto.emailAddress + '_' + type + '_' + date.getTime() + '_' + i.id;
key = type + '_' + i.sentDate + '_' + i.id;
} else {
key = crypto.emailAddress + '_' + type + '_' + i.id;
key = type + '_' + i.id;
}
items.push({
@ -52,7 +52,7 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) {
*/
this.listEncryptedItems = function(type, offset, num, callback) {
// fetch all items of a certain type from the data-store
jsonDao.list(crypto.emailAddress + '_' + type, offset, num, function(encryptedList) {
jsonDao.list(type, offset, num, function(encryptedList) {
callback(null, encryptedList);
});

View File

@ -5,7 +5,7 @@ app.dao.LawnchairDAO = function(Lawnchair) {
'use strict';
var db = new Lawnchair({
name: 'data-store'
name: 'dataStore'
}, function(lc) {
if (!lc) {
throw new Error('Lawnchair init failed!');
@ -63,14 +63,6 @@ app.dao.LawnchairDAO = function(Lawnchair) {
}
}
// sort keys by type and date
matchingKeys = _.sortBy(matchingKeys, function(key) {
parts = key.split('_');
timeStr = parts[parts.length - 2];
time = parseInt(timeStr, 10);
return time;
});
// if num is null, list all items
num = (num !== null) ? num : matchingKeys.length;

View File

@ -46,6 +46,10 @@ asyncTest("Encrypt list for user", 2, function() {
ok(!err);
equal(encryptedList.length, devicestorage_test.list.length, 'Encrypt list');
encryptedList.forEach(function(i) {
i.sentDate = _.findWhere(devicestorage_test.list, {id: i.id}).sentDate;
});
devicestorage_test.encryptedList = encryptedList;
start();
});
@ -67,7 +71,7 @@ asyncTest("List items", 4, function() {
num = 6;
// list encrypted items from storage
devicestorage_test.storage.listEncryptedItems('email_inbox_5', offset, num, function(err, encryptedList) {
devicestorage_test.storage.listEncryptedItems('email_inbox', offset, num, function(err, encryptedList) {
ok(!err);
// decrypt list
@ -75,15 +79,8 @@ asyncTest("List items", 4, function() {
ok(!err);
equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)');
var decrypted, orig = devicestorage_test.list[54];
// check ids
for (var i = 0; i < decryptedList.length; i++) {
if (decryptedList[i].id === orig.id && decryptedList[i].from === orig.from) {
deepEqual(decryptedList[i], orig, 'Messages decrypted correctly');
break;
}
}
var origSet = devicestorage_test.list.splice(92, num);
deepEqual(decryptedList, origSet, 'Messages decrypted correctly');
start();
});