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);
|
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) {
|
MessageDb.fromStorage = function(data) {
|
||||||
var spl = data.key.split('-');
|
var parsed = MessageDb.parseKey(data.key);
|
||||||
var to = spl[1];
|
|
||||||
var ts = +spl[2];
|
|
||||||
var message = data.value;
|
var message = data.value;
|
||||||
message.ts = ts;
|
message.ts = parsed.ts;
|
||||||
message.to = to;
|
message.to = parsed.to;
|
||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,8 +125,13 @@ MessageDb.prototype.getMessages = function(to, lower_ts, upper_ts, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MessageDb.prototype.removeUpTo = function(ts) {
|
MessageDb.prototype.removeUpTo = function(ts) {
|
||||||
|
preconditions.checkArgument(ts);
|
||||||
|
preconditions.checkArgument(typeof ts === 'number');
|
||||||
var opts = {};
|
var opts = {};
|
||||||
db.createKeyStream(opts);
|
db.createKeyStream(opts)
|
||||||
|
.on('data', function(key) {
|
||||||
|
console.log('key=', key)
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = soop(MessageDb);
|
module.exports = soop(MessageDb);
|
||||||
|
|||||||
@ -108,6 +108,10 @@ describe('MessageDb', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should be able #removeUpTo', function() {
|
||||||
|
var mdb = sharedMDB;
|
||||||
|
mdb.removeUpTo(microtime.now());
|
||||||
|
});
|
||||||
it('should be able to close instance', function() {
|
it('should be able to close instance', function() {
|
||||||
var mdb = new MessageDb(opts);
|
var mdb = new MessageDb(opts);
|
||||||
mdb.close();
|
mdb.close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user