mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
event cache
This commit is contained in:
parent
4dff74827b
commit
702e35650f
@ -14,6 +14,8 @@ class Event < ActiveRecord::Base
|
||||
|
||||
after_create :event_recurrence
|
||||
before_save :update_nb_free_places
|
||||
# update event updated_at for index cache
|
||||
after_save -> { self.touch }
|
||||
|
||||
def name
|
||||
title
|
||||
|
@ -2,12 +2,12 @@ class EventPolicy < ApplicationPolicy
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
if user.nil? or (user and !user.is_admin?)
|
||||
scope.includes(:event_image, :event_files, :availability)
|
||||
scope.includes(:event_image, :event_files, :availability, :categories)
|
||||
.where('availabilities.start_at >= ?', Time.now)
|
||||
.order('availabilities.start_at ASC')
|
||||
.references(:availabilities)
|
||||
else
|
||||
scope.includes(:event_image, :event_files, :availability)
|
||||
scope.includes(:event_image, :event_files, :availability, :categories)
|
||||
.order('availabilities.start_at DESC')
|
||||
.references(:availabilities)
|
||||
end
|
||||
|
@ -1,7 +1,8 @@
|
||||
json.array!(@events) do |event|
|
||||
json.partial! 'api/events/event', event: event
|
||||
json.event_image_small event.event_image.attachment.small.url if event.event_image
|
||||
json.url event_url(event, format: :json)
|
||||
json.nb_total_events @total
|
||||
json.cache! [@events, @page] do
|
||||
json.array!(@events) do |event|
|
||||
json.partial! 'api/events/event', event: event
|
||||
json.event_image_small event.event_image.attachment.small.url if event.event_image
|
||||
json.url event_url(event, format: :json)
|
||||
json.nb_total_events @total
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user