Skip to content

Commit

Permalink
Fixing issue with prefetching ddb page when at the end of stream
Browse files Browse the repository at this point in the history
  • Loading branch information
czirker committed Nov 13, 2023
1 parent 37b45d7 commit ddfbad8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/stream/leo-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ module.exports = function(configure) {
}

let getEvents;

let getEventsInit = () => { };
if (leoEvent.v >= 2 || !leoEvent.max_eid) {
var max_eid = (configure.registry && configure.registry.__cron && configure.registry.__cron.maxeid) || opts.maxOverride || leoEvent.max_eid || ls.eventIdFromTimestamp(Date.now(), "full", 0);
var table_name = configure.resources.LeoStream;
Expand Down Expand Up @@ -1586,7 +1586,10 @@ module.exports = function(configure) {
};

// Bootstrap the process to query the table
let nextGetEventPromise = new Promise((resolve) => getEventsQuery((err, data) => resolve({ err, data })));
let nextGetEventPromise;
getEventsInit = () => {
nextGetEventPromise = new Promise((resolve) => getEventsQuery((err, data) => resolve({ err, data })));
};

getEvents = function(callback) {
nextGetEventPromise.then((response) => {
Expand Down Expand Up @@ -1627,6 +1630,7 @@ module.exports = function(configure) {
eid: start
});
if (usingSnapshot || max_eid.localeCompare(start) > 0) {
getEventsInit();
async.whilst(() => {
logger.debug("checking next loop, loops remaining ", hasLoops, ", Time Remaining:", opts.stopTime - moment.now());
hasTime = hasTime && (opts.stopTime > moment.now());
Expand Down

0 comments on commit ddfbad8

Please sign in to comment.