mirror of
https://github.com/moparisthebest/mail
synced 2025-02-18 07:50:34 -05:00
put sentDate in lawnchair key, reducing sort complexity
This commit is contained in:
parent
ef05addc31
commit
5a2a559485
@ -27,9 +27,9 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) {
|
|||||||
// put date in key if available... for easy querying
|
// put date in key if available... for easy querying
|
||||||
if (i.sentDate) {
|
if (i.sentDate) {
|
||||||
date = util.parseDate(i.sentDate);
|
date = util.parseDate(i.sentDate);
|
||||||
key = crypto.emailAddress + '_' + type + '_' + date.getTime() + '_' + i.id;
|
key = type + '_' + i.sentDate + '_' + i.id;
|
||||||
} else {
|
} else {
|
||||||
key = crypto.emailAddress + '_' + type + '_' + i.id;
|
key = type + '_' + i.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
@ -52,7 +52,7 @@ app.dao.DeviceStorage = function(util, crypto, jsonDao, sqlcipherDao) {
|
|||||||
*/
|
*/
|
||||||
this.listEncryptedItems = function(type, offset, num, callback) {
|
this.listEncryptedItems = function(type, offset, num, callback) {
|
||||||
// fetch all items of a certain type from the data-store
|
// 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);
|
callback(null, encryptedList);
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ app.dao.LawnchairDAO = function(Lawnchair) {
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var db = new Lawnchair({
|
var db = new Lawnchair({
|
||||||
name: 'data-store'
|
name: 'dataStore'
|
||||||
}, function(lc) {
|
}, function(lc) {
|
||||||
if (!lc) {
|
if (!lc) {
|
||||||
throw new Error('Lawnchair init failed!');
|
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
|
// if num is null, list all items
|
||||||
num = (num !== null) ? num : matchingKeys.length;
|
num = (num !== null) ? num : matchingKeys.length;
|
||||||
|
|
||||||
|
@ -46,6 +46,10 @@ asyncTest("Encrypt list for user", 2, function() {
|
|||||||
ok(!err);
|
ok(!err);
|
||||||
equal(encryptedList.length, devicestorage_test.list.length, 'Encrypt list');
|
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;
|
devicestorage_test.encryptedList = encryptedList;
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
@ -67,7 +71,7 @@ asyncTest("List items", 4, function() {
|
|||||||
num = 6;
|
num = 6;
|
||||||
|
|
||||||
// list encrypted items from storage
|
// 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);
|
ok(!err);
|
||||||
|
|
||||||
// decrypt list
|
// decrypt list
|
||||||
@ -75,15 +79,8 @@ asyncTest("List items", 4, function() {
|
|||||||
ok(!err);
|
ok(!err);
|
||||||
equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)');
|
equal(decryptedList.length, num, 'Found ' + decryptedList.length + ' items in store (and decrypted)');
|
||||||
|
|
||||||
var decrypted, orig = devicestorage_test.list[54];
|
var origSet = devicestorage_test.list.splice(92, num);
|
||||||
|
deepEqual(decryptedList, origSet, 'Messages decrypted correctly');
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user