Don't search for an old hash in a file when a cache is deprecated

This commit is contained in:
yflory 2022-11-30 14:39:38 +01:00
parent 15d9a9c703
commit c75a75b243

View File

@ -428,6 +428,7 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
// lastKnownhash === -1 means we want the complete history
if (lastKnownHash === -1) { return void cb(null, 0); }
let offset = -1;
nThen((waitFor) => {
getIndex(Env, channelName, waitFor((err, index) => {
@ -436,8 +437,11 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
// check if the "hash" the client is requesting exists in the index
const lkh = index.offsetByHash[lastKnownHash];
// fall through to the next block if the offset of the hash in question is not in memory
if (lastKnownHash && typeof(lkh) !== "number") { return; }
// Hash too old or no longer exists, empty cache
if (lastKnownHash && typeof(lkh) !== "number") {
waitFor.abort();
return void cb(new Error('EUNKNOWN'));
}
// If we have a lastKnownHash or we didn't ask for one, we don't need the next blocks
waitFor.abort();
@ -477,6 +481,9 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
cb(null, lkh);
}));
}).nThen((w) => {
// XXX entire block and getHashOffset to remove?
// skip past this block if the offset is anything other than -1
// this basically makes these first two nThen blocks behave like if-else
if (offset !== -1) { return; }