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

Checkins with a delay are sorted wrong #1382

Open
Oxbowatos opened this issue Feb 8, 2023 · 2 comments · May be fixed by #2703
Open

Checkins with a delay are sorted wrong #1382

Oxbowatos opened this issue Feb 8, 2023 · 2 comments · May be fixed by #2703
Labels
bug Something isn't working database help wanted Extra attention is needed

Comments

@Oxbowatos
Copy link

Describe the bug
If e.g. I checkin in a train which derparting at 7am and I get on a train departing 6:30am but has 1 hour delay, the delayed checkin is sorted under the first checkin.

It also happens on the Global Dashboard and Home Dashboard that it's sorted wrong

To Reproduce
Steps to reproduce the behavior:

  1. Checkin in a normal Train
  2. At your Stop search for a delayed Train/Bus/etc (where the sheduled departure time is under the sheduled departure time of your first Checkin)
  3. Look how the Checkins are sorted
  4. See that the Checkin with Delay is sorted under the Checkins without Delay

Expected behavior
That the Page sorts the Checkins with the delayed departure time not only the sheduled departure time.

Screenshots
If applicable, add screenshots to help explain your problem.

See how its sorted: (Deleted some fields for privacy reason)
grafik

Desktop (please complete the following information):
Any Browser

Smartphone (please complete the following information):
Any Smartphone

@Oxbowatos Oxbowatos added the bug Something isn't working label Feb 8, 2023
@MrKrisKrisu
Copy link
Member

This is our current query for the private dashboard:

return Status::with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'trainCheckin',
'trainCheckin.originStation', 'trainCheckin.destinationStation',
'trainCheckin.HafasTrip.stopovers.trainStation'
])
->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id')
->select('statuses.*')
->where('train_checkins.departure', '<', Carbon::now()->addMinutes(20))
->orderBy('train_checkins.departure', 'desc')
->whereIn('statuses.user_id', $followingIDs)
->whereNotIn('statuses.user_id', $user->mutedUsers->pluck('id'))
->whereIn('statuses.visibility', [
StatusVisibility::PUBLIC->value,
StatusVisibility::FOLLOWERS->value,
StatusVisibility::AUTHENTICATED->value
])
->orWhere('statuses.user_id', $user->id)
->latest()
->simplePaginate(15);

We sort here only according to the planned departure of the Journey:

->orderBy('train_checkins.departure', 'desc')

In order for us to aggregate the data correctly directly we would need to do the following sorts in order:

  1. if isset DESC {join}.train_checkins.manual_departure
  2. DESC {join}.train_checkins.{join}.train_stopovers.{real_departure}.
  3. DESC {join}.train_checkins.{join}.train_stopovers.{planned_departure}.

Since our data structure is a bit complex to build a meaningful and performant query for it I would suggest to do the sorting only on the frontend level so that it looks properly sorted to the user.

@MrKrisKrisu
Copy link
Member

ER-Diagram with the relevant tables:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working database help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants