Optimisations
This commit is contained in:
parent
566929a3f5
commit
a82c832354
@ -83,10 +83,8 @@ class EventsController < ApplicationController
|
||||
private
|
||||
|
||||
def set_events
|
||||
# The 3000 limit is purely arbitrary...
|
||||
@events = apply_scopes Event.moderated.order('id desc')
|
||||
.limit(params[:format] == 'rss' ? 20 : 3000)
|
||||
@events = @events.includes :region if params[:format].present?
|
||||
@events = apply_scopes Event.moderated
|
||||
@events = @events.limit(20) if params[:format] == 'rss'
|
||||
end
|
||||
|
||||
def new_event
|
||||
|
@ -36,7 +36,7 @@ class TagsController < InheritedResources::Base
|
||||
@orgas = (apply_scopes(Orga.moderated.active) +
|
||||
Orga.moderated.active
|
||||
.where(
|
||||
'lower(name) like lower(?)',
|
||||
'lower(orgas.name) like lower(?)',
|
||||
"%#{params[:id].tr '-', '%'}%"
|
||||
)
|
||||
).uniq
|
||||
|
@ -42,7 +42,10 @@ class Event < ApplicationRecord
|
||||
|
||||
after_destroy EventCallbacks
|
||||
|
||||
default_scope { includes(:taggings, :region) }
|
||||
# The 3000 limit is purely arbitrary...
|
||||
default_scope do
|
||||
joins(:region).includes(:base_tags).order('events.id desc').limit(3000)
|
||||
end
|
||||
scope :moderated, ->(*) { where moderated: true }
|
||||
scope :unmoderated, ->(*) { where moderated: false }
|
||||
scope :past, -> { where 'start_time <= ?', Time.zone.now }
|
||||
@ -60,8 +63,7 @@ class Event < ApplicationRecord
|
||||
end)
|
||||
scope :period, (lambda do |year, week|
|
||||
start_date = Date.commercial(
|
||||
year.to_i,
|
||||
(week || (Time.zone.today + 7.days).cweek).to_i
|
||||
year.to_i, (week || (Time.zone.today + 7.days).cweek).to_i
|
||||
)
|
||||
where '? <= end_time and start_time <= ?',
|
||||
start_date, start_date.end_of_week.end_of_day
|
||||
@ -79,9 +81,6 @@ class Event < ApplicationRecord
|
||||
before_validation on: :create do
|
||||
self.submission_time = Time.zone.now
|
||||
self.decision_time = Time.zone.now
|
||||
|
||||
# Populate submitter using contact info if absent
|
||||
self.submitter ||= contact
|
||||
end
|
||||
|
||||
before_validation on: :update do
|
||||
@ -110,8 +109,7 @@ class Event < ApplicationRecord
|
||||
|
||||
def to_tweet
|
||||
url = Rails.application.routes.url_helpers.event_url(
|
||||
self,
|
||||
host: ActionMailer::Base.default_url_options[:host]
|
||||
self, host: ActionMailer::Base.default_url_options[:host]
|
||||
)
|
||||
|
||||
tweet = "#{self} #{url}"
|
||||
|
@ -21,6 +21,7 @@ class Orga < ApplicationRecord
|
||||
# after_validation :geocode, if: -> (obj) { obj.saved_change_to_address? }
|
||||
after_validation :geocode
|
||||
|
||||
default_scope { includes(:region, :kind, :base_tags).order('orgas.id desc') }
|
||||
scope :active, ->(value = true) { where active: value }
|
||||
scope :inactive, ->(value = false) { where active: value }
|
||||
scope :moderated, -> { where moderated: true }
|
||||
|
@ -22,7 +22,7 @@ Kind.create name: 'glug', icon: 'support'
|
||||
Kind.create name: 'provider', icon: 'tty'
|
||||
Kind.create name: 'institution', icon: 'institution'
|
||||
|
||||
# rubocop:disable Metrics/LineLength
|
||||
# rubocop:disable Layout/LineLength
|
||||
I18n::Backend::ActiveRecord::Translation.create(
|
||||
[
|
||||
{ locale: 'fr', key: 'mail_suffix', value: '[AdL] ' },
|
||||
@ -410,4 +410,4 @@ Ces recommandations de modération sont à discuter et à améliorer au fur et
|
||||
" }
|
||||
]
|
||||
)
|
||||
# rubocop:enable Metrics/LineLength
|
||||
# rubocop:enable Layout/LineLength
|
||||
|
@ -24,7 +24,7 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
|
||||
start_time: @event.start_time, end_time: @event.end_time,
|
||||
description: @event.description,
|
||||
city: @event.city, region_id: @event.region.id,
|
||||
url: @event.url, contact: @event.contact, tag_list: 'helo world'
|
||||
url: @event.url, submitter: @event.contact, tag_list: 'helo world'
|
||||
} }
|
||||
|
||||
assert_empty assigns(:event).errors
|
||||
@ -40,7 +40,7 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
|
||||
start_time: @event.start_time, end_time: @event.end_time,
|
||||
description: @event.description,
|
||||
city: @event.city, region_id: @event.region.id,
|
||||
url: @event.url, contact: @event.contact, tag_list: 'helo world'
|
||||
url: @event.url, submitter: @event.contact, tag_list: 'helo world'
|
||||
} }
|
||||
|
||||
assert_empty assigns(:event).errors.messages
|
||||
|
@ -13,7 +13,7 @@ class EventCallbacksTest < ActiveSupport::TestCase
|
||||
description: 'et hop!',
|
||||
city: City.first, region: Region.first,
|
||||
url: 'http://example.com',
|
||||
contact: 'contact@example.com',
|
||||
submitter: 'contact@example.com',
|
||||
tag_list: 'hello world'
|
||||
)
|
||||
assert_difference 'Event.count' do
|
||||
@ -29,7 +29,7 @@ class EventCallbacksTest < ActiveSupport::TestCase
|
||||
description: 'et hop!',
|
||||
city: City.first, region: Region.first,
|
||||
url: 'http://example.com',
|
||||
contact: 'contact@example.com',
|
||||
submitter: 'contact@example.com',
|
||||
tag_list: 'hello world'
|
||||
)
|
||||
|
||||
|
@ -17,7 +17,6 @@ class EventTest < ActiveSupport::TestCase
|
||||
city: City.first,
|
||||
region: Region.first,
|
||||
url: 'http://example.com',
|
||||
contact: 'contact@example.com',
|
||||
submitter: 'submitter@example.com',
|
||||
tag_list: 'hello world'
|
||||
)
|
||||
@ -40,6 +39,7 @@ class EventTest < ActiveSupport::TestCase
|
||||
region: Region.first,
|
||||
url: 'http://example.com',
|
||||
contact: 'contact@example.com',
|
||||
submitter: 'contact@example.com',
|
||||
tag_list: 'hello world'
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ class EventTest < ActiveSupport::TestCase
|
||||
city: City.first,
|
||||
region: Region.first,
|
||||
url: 'http://example.com',
|
||||
contact: 'contact@example.com',
|
||||
submitter: 'contact@example.com',
|
||||
tag_list: 'hello world'
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user