main ← fix-event-not-found-after-being-moved-to-earlier-date
opened 03:15PM - 05 Dec 25 UTC
Events that were edited to an earlier date multiple times were not appearing in …EventFinder search results when querying their new date range.
The SQL query in `EventFinder.latest_event_date_join` used a different ordering than the Ruby `Event#current_event_date` logic:
- SQL: `ORDER BY finished_at DESC NULLS FIRST, starts_at DESC`
- Ruby: pending dates by `starts_at`, finished dates by `updated_at, id`
This mismatch caused the SQL to return a different "current" event date than what the Ruby model expected, breaking date range filtering for rescheduled events.
- Extracted duplicated logic in `Event#starts_at` and `Event#ends_at` into a shared `current_event_date` method
- Updated the SQL ordering to mirror the Ruby logic: `finished_at IS NOT NULL, CASE WHEN finished_at IS NULL THEN starts_at ELSE updated_at END DESC, id DESC`
- Updated the database index to support the new query
- Added regression test for the "event edited to earlier date" scenario
Bug report - https://meta.discourse.org/t/date-range-seems-wrong/389891