Skip to content

Commit

Permalink
allow draft trips to show up if pipeline has never been run
Browse files Browse the repository at this point in the history
If a user has just joined and none of their data has ever been through the pipeline, they will have a pipelineRange of `{start_ts: null, end_ts: null}`.
In this case, there is no point in querying for `analysis/composite_trip`s because no analysis entries have been created yet

However, the user might have travel that hasn't been through the pipeline yet. So instead of immediately returning early from fetchTripsInRange, let's allow readUnprocessedPromise to execute, using 0 as the lower ts bound since pipelineRange end_ts will be null.

I tested this by creating a brand new user, simulating a trip, and reloading the diary. The draft trip shows up without ever running the pipeline.
  • Loading branch information
JGreenlee committed Dec 9, 2024
1 parent 0d60712 commit 970e50c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions www/js/TimelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,33 +221,34 @@ export const useTimelineContext = (): ContextProps => {
}

async function fetchTripsInRange(dateRange: [string, string]) {
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
logDebug('No pipelineRange yet, returning empty lists');
return [[], []];
}
logDebug('Timeline: fetchTripsInRange from ' + dateRange[0] + ' to ' + dateRange[1]);

const [startTs, endTs] = isoDateRangeToTsRange(dateRange);
const maxStartTs = Math.max(startTs, pipelineRange.start_ts); // ensure that we don't read before the pipeline start
const minEndTs = Math.min(endTs, pipelineRange.end_ts); // ensure that we don't read after the pipeline end

const readCompositePromise = readAllCompositeTrips(maxStartTs, minEndTs);
let readCompositePromise; // comment
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
readCompositePromise = Promise.resolve([]);
} else {
const maxStartTs = Math.max(startTs, pipelineRange.start_ts); // ensure that we don't read before the pipeline start
const minEndTs = Math.min(endTs, pipelineRange.end_ts); // ensure that we don't read after the pipeline end
readCompositePromise = readAllCompositeTrips(maxStartTs, minEndTs);
}

let readUnprocessedPromise;
if (endTs >= pipelineRange.end_ts) {
if (pipelineRange?.end_ts && pipelineRange.end_ts > endTs) {
readUnprocessedPromise = Promise.resolve([]);
} else {
let lastProcessedTrip: CompositeTrip | undefined;
if (timelineMap) {
lastProcessedTrip = [...timelineMap?.values()]
.reverse()
.find((trip) => trip.origin_key.includes('trip')) as CompositeTrip;
}
readUnprocessedPromise = readUnprocessedTrips(
Math.max(pipelineRange.end_ts, startTs),
Math.max(pipelineRange?.end_ts || 0, startTs),
endTs,
appConfig,
lastProcessedTrip,
);
} else {
readUnprocessedPromise = Promise.resolve([]);
}

const results = await Promise.all([readCompositePromise, readUnprocessedPromise]);
Expand Down

0 comments on commit 970e50c

Please sign in to comment.