Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 13 additions & 7 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ class EventsController < ApplicationController
def index
fresh_when(latest_model_updated, etag: latest_model_updated)

events = [Workshop.past.includes(:chapter,
:sponsors).joins(:chapter).merge(Chapter.active).limit(RECENT_EVENTS_DISPLAY_LIMIT)]
events << Meeting.past.includes(:venue).limit(RECENT_EVENTS_DISPLAY_LIMIT)
events << Event.past.includes(:venue, :sponsors, :sponsorships).limit(RECENT_EVENTS_DISPLAY_LIMIT)
events = [Workshop.past
.includes(:chapter, :sponsors, :host, :permissions)
.joins(:chapter)
.merge(Chapter.active)
.limit(RECENT_EVENTS_DISPLAY_LIMIT)]
events << Meeting.past.includes(:venue, :permissions).limit(RECENT_EVENTS_DISPLAY_LIMIT)
events << Event.past.includes(:venue, :sponsors, :sponsorships, :permissions).limit(RECENT_EVENTS_DISPLAY_LIMIT)
events = events.compact.flatten.sort_by(&:date_and_time).reverse.first(RECENT_EVENTS_DISPLAY_LIMIT)
events_hash_grouped_by_date = events.group_by(&:date)
@past_events = events_hash_grouped_by_date.map.each_with_object({}) do |(key, value), hash|
hash[key] = EventPresenter.decorate_collection(value)
end

events = [Workshop.includes(:chapter, :sponsors).upcoming.joins(:chapter).merge(Chapter.active)]
events << Meeting.upcoming.all
events << Event.upcoming.includes(:venue, :sponsors, :sponsorships).all
events = [Workshop.upcoming
.includes(:chapter, :sponsors, :host, :permissions)
.joins(:chapter)
.merge(Chapter.active)]
events << Meeting.upcoming.includes(:venue, :permissions).all
events << Event.upcoming.includes(:venue, :sponsors, :sponsorships, :permissions).all
events = events.compact.flatten.sort_by(&:date_and_time).group_by(&:date)
@events = events.map.each_with_object({}) do |(key, value), hash|
hash[key] = EventPresenter.decorate_collection(value)
Expand Down
17 changes: 5 additions & 12 deletions app/models/workshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Workshop < ApplicationRecord
has_many :invitations, class_name: 'WorkshopInvitation'
has_many :workshop_sponsors
has_many :sponsors, through: :workshop_sponsors
has_one :workshop_host, -> { where(workshop_sponsors: { host: true }) },
class_name: 'WorkshopSponsor',
inverse_of: :workshop
has_one :host, through: :workshop_host, source: :sponsor
has_many :organisers, -> { where('permissions.name' => 'organiser') }, through: :permissions, source: :members
has_many :feedbacks

Expand All @@ -31,18 +35,7 @@ class Workshop < ApplicationRecord
before_validation :set_opens_at

def host
sql = <<~SQL
SELECT sponsors.*
FROM sponsors
LEFT JOIN workshop_sponsors ON workshop_sponsors.sponsor_id = sponsors.id
WHERE workshop_sponsors.workshop_id = ?
AND workshop_sponsors.host = TRUE
AND sponsors.id = workshop_sponsors.sponsor_id
ORDER BY sponsors.updated_at DESC, workshop_sponsors.id ASC
LIMIT 1
SQL

Sponsor.find_by_sql([sql, id]).first
workshop_host&.sponsor
end

def waiting_list
Expand Down
2 changes: 1 addition & 1 deletion app/models/workshop_sponsor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class WorkshopSponsor < ApplicationRecord
belongs_to :sponsor
belongs_to :workshop
belongs_to :workshop, inverse_of: :workshop_sponsors

validates :sponsor_id, uniqueness: { scope: :workshop_id, message: :already_sponsoring }
end
2 changes: 1 addition & 1 deletion app/presenters/workshop_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def attending_and_available_coach_spots
end

def venue
model.host
@venue ||= model.host
end

def organisers
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20260224130000_add_index_workshop_sponsors_host.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexWorkshopSponsorsHost < ActiveRecord::Migration[8.1]
def change
add_index :workshop_sponsors, %i[workshop_id host], name: 'index_workshop_sponsors_on_workshop_id_and_host'
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_02_24_120000) do
ActiveRecord::Schema[8.1].define(version: 2026_02_24_130000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"

Expand Down Expand Up @@ -565,6 +565,7 @@
t.datetime "updated_at", precision: nil
t.integer "workshop_id"
t.index ["sponsor_id"], name: "index_workshop_sponsors_on_sponsor_id"
t.index ["workshop_id", "host"], name: "index_workshop_sponsors_on_workshop_id_and_host"
t.index ["workshop_id"], name: "index_workshop_sponsors_on_workshop_id"
end

Expand Down
Loading