cleaner plugin: optimize getMessages
This commit is contained in:
parent
fe682c173f
commit
8dc4af654b
@ -83,13 +83,21 @@ MessageDb.prototype.authenticate = function(m) {
|
||||
return AuthMessage._verify(frompubkey, sig, encrypted);
|
||||
};
|
||||
|
||||
MessageDb.parseKey = function(key) {
|
||||
var ret = {};
|
||||
var spl = key.split('-');
|
||||
|
||||
ret.to = spl[1];
|
||||
ret.ts = +spl[2];
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
MessageDb.fromStorage = function(data) {
|
||||
var spl = data.key.split('-');
|
||||
var to = spl[1];
|
||||
var ts = +spl[2];
|
||||
var parsed = MessageDb.parseKey(data.key);
|
||||
var message = data.value;
|
||||
message.ts = ts;
|
||||
message.to = to;
|
||||
message.ts = parsed.ts;
|
||||
message.to = parsed.to;
|
||||
return message;
|
||||
};
|
||||
|
||||
@ -117,8 +125,13 @@ MessageDb.prototype.getMessages = function(to, lower_ts, upper_ts, cb) {
|
||||
};
|
||||
|
||||
MessageDb.prototype.removeUpTo = function(ts) {
|
||||
preconditions.checkArgument(ts);
|
||||
preconditions.checkArgument(typeof ts === 'number');
|
||||
var opts = {};
|
||||
db.createKeyStream(opts);
|
||||
db.createKeyStream(opts)
|
||||
.on('data', function(key) {
|
||||
console.log('key=', key)
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = soop(MessageDb);
|
||||
|
||||
@ -108,6 +108,10 @@ describe('MessageDb', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should be able #removeUpTo', function() {
|
||||
var mdb = sharedMDB;
|
||||
mdb.removeUpTo(microtime.now());
|
||||
});
|
||||
it('should be able to close instance', function() {
|
||||
var mdb = new MessageDb(opts);
|
||||
mdb.close();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user