Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking ā€œSign up for GitHubā€, you agree to our terms of service and privacy statement. Weā€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

šŸ› Fix draft trips not showing up for (i) unpushed transitions (ii) fresh user #1189

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow draft trips to show up if pipeline has never been run
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
commit 970e50c0049a2e24cf6c129f907624f3e462f742
25 changes: 13 additions & 12 deletions www/js/TimelineContext.ts
Original file line number Diff line number Diff line change
@@ -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]);