WIP history-keeper fixes

This commit is contained in:
ansuz
2020-04-01 11:48:16 -04:00
parent 1a825ad664
commit ed5d97f899
3 changed files with 79 additions and 25 deletions

View File

@@ -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;
}