WIP history-keeper fixes
This commit is contained in:
@@ -395,7 +395,7 @@ const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash) {
|
||||
* -1 if you didn't find it
|
||||
|
||||
*/
|
||||
const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
|
||||
const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => { // XXX
|
||||
const cb = Util.once(Util.mkAsync(_cb));
|
||||
|
||||
// lastKnownhash === -1 means we want the complete history
|
||||
@@ -417,8 +417,9 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
|
||||
// without specifying the hash, and just trust the server to give them the relevant data.
|
||||
// QUESTION: does this mean mailboxes are causing the server to store too much stuff in memory?
|
||||
if (lastKnownHash && typeof(lkh) !== "number") {
|
||||
waitFor.abort();
|
||||
return void cb(new Error('EINVAL'));
|
||||
return; // XXX fall through to find the offset since it isn't cached
|
||||
//waitFor.abort();
|
||||
//return void cb(new Error('EINVAL'));
|
||||
}
|
||||
|
||||
// Since last 2 checkpoints
|
||||
@@ -474,7 +475,7 @@ const getHistoryAsync = (Env, channelName, lastKnownHash, beforeHash, handler, c
|
||||
|
||||
let offset = -1;
|
||||
nThen((waitFor) => {
|
||||
getHistoryOffset(Env, channelName, lastKnownHash, waitFor((err, os) => {
|
||||
getHistoryOffset(Env, channelName, lastKnownHash, waitFor((err, os) => { // XXX
|
||||
if (err) {
|
||||
waitFor.abort();
|
||||
return void cb(err);
|
||||
@@ -482,7 +483,11 @@ const getHistoryAsync = (Env, channelName, lastKnownHash, beforeHash, handler, c
|
||||
offset = os;
|
||||
}));
|
||||
}).nThen((waitFor) => {
|
||||
if (offset === -1) { return void cb(new Error("could not find offset")); }
|
||||
if (offset === -1) {
|
||||
return void cb(new Error('EUNKNOWN'));
|
||||
console.log(lastKnownHash);
|
||||
return void cb(new Error("could not find offset")); // XXX EUNKNOWN
|
||||
}
|
||||
const start = (beforeHash) ? 0 : offset;
|
||||
store.readMessagesBin(channelName, start, (msgObj, readMore, abort) => {
|
||||
if (beforeHash && msgObj.offset >= offset) { return void abort(); }
|
||||
@@ -630,7 +635,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) {
|
||||
}, (err) => {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
if (err.message !== 'EINVAL') { Log.error("HK_GET_HISTORY", err); }
|
||||
const parsedMsg = {error:err.message, channel: channelName, txid: txid};
|
||||
const parsedMsg = {error:err.message, channel: channelName, txid: txid}; // XXX
|
||||
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg)]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,8 @@ const computeIndex = function (data, cb) {
|
||||
messageBuf = [];
|
||||
}
|
||||
} else if (messageBuf.length > 100 && cpIndex.length === 0) {
|
||||
messageBuf = messageBuf.slice(0, 50);
|
||||
// take the last 50 messages
|
||||
messageBuf = messageBuf.slice(-50);
|
||||
}
|
||||
// if it's not metadata or a checkpoint then it should be a regular message
|
||||
// store it in the buffer
|
||||
@@ -352,7 +353,8 @@ const getMultipleFileSize = function (data, cb) {
|
||||
|
||||
const getHashOffset = function (data, cb) {
|
||||
const channelName = data.channel;
|
||||
const lastKnownHash = data.lastKnownHash;
|
||||
const lastKnownHash = data.hash;
|
||||
if (typeof(lastKnownHash) !== 'string') { return void cb("INVALID_HASH"); }
|
||||
|
||||
var offset = -1;
|
||||
store.readMessagesBin(channelName, 0, (msgObj, readMore, abort) => {
|
||||
|
||||
Reference in New Issue
Block a user