Skip to content

Extract the events list UNION query out of EventsController #2937

Open

Description

@mroderick

Problem

EventsController builds the paginated upcoming/past events listing inside the controller: paginated_events (~80 lines) constructs a raw Arel UNION ALL across workshops, meetings, and events, plus a separate COUNT query and manual Pagy wiring, and load_events re-hydrates AR objects from the returned id/type pairs. fetch_upcoming_events and fetch_past_events are also near-duplicates of each other.

This is query logic, not HTTP coordination, and it makes the controller the largest non-admin one in the app. The repo already has app/queries/ (DashboardQuery, SponsorsSearch) — this work belongs there.

Proposed change

  • Move the UNION ALL construction, count, pagination, and re-hydration into a single query class, e.g. app/queries/events_feed_query.rb, with an upcoming: flag so fetch_upcoming_events / fetch_past_events collapse into one method.
  • Controller keeps only: parse params[:page], call the query, assign for the view.

Acceptance

  • EventsController#upcoming / #past are a few lines each and contain no Arel.
  • Existing behaviour unchanged: same ordering, grouping by date, 20 rows/page, DB-level count and pagination.
  • bundle exec rspec spec/controllers/events_controller_spec.rb (and the feature specs touching the events pages) pass.

Activity

  1. davidmillen50 commented on Oct 13, 2026

    @davidmillen50
    Contributor

    WIP #3035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions