1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

cache last event and optimise last subscript api

This commit is contained in:
Peng DU 2016-06-27 10:55:51 +02:00
parent 0bb4665b4a
commit 68e45c0460
3 changed files with 10 additions and 8 deletions

View File

@ -4,13 +4,14 @@ class API::EventsController < API::ApiController
def index
@events = policy_scope(Event)
@total = @events.count
@events = @events.page(params[:page]).per(12)
@page = params[:page]
@events = @events.page(@page).per(12)
end
# GET /events/upcoming/:limit
def upcoming
limit = params[:limit]
@events = Event.includes(:event_image, :event_files, :availability)
@events = Event.includes(:event_image, :event_files, :availability, :categories)
.where('availabilities.start_at >= ?', Time.now)
.order('availabilities.start_at ASC').references(:availabilities).limit(limit)
end

View File

@ -13,7 +13,7 @@ class API::MembersController < API::ApiController
end
def last_subscribed
@members = User.active.with_role(:member).includes(:profile).where('is_allow_contact = true AND confirmed_at IS NOT NULL').order('created_at desc').limit(params[:last])
@members = User.active.with_role(:member).includes(profile: [:user_avatar]).where('is_allow_contact = true AND confirmed_at IS NOT NULL').order('created_at desc').limit(params[:last])
@requested_attributes = ['profile']
render :index
end

View File

@ -1,6 +1,7 @@
json.array!(@events) do |event|
json.partial! 'api/events/event', event: event
json.event_image_medium event.event_image.attachment.medium.url if event.event_image
json.url event_url(event, format: :json)
json.cache! @events do
json.array!(@events) do |event|
json.partial! 'api/events/event', event: event
json.event_image_medium event.event_image.attachment.medium.url if event.event_image
json.url event_url(event, format: :json)
end
end