1
0
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:
Peng DU 2016-06-24 18:26:11 +02:00
parent 4dff74827b
commit 702e35650f
3 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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