Skip to content
Snippets Groups Projects
Commit dc31a459 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

cache learning object serializer

parent f0d9a51a
No related branches found
No related tags found
No related merge requests found
module Paginator
extend ActiveSupport::Concern
def paginate (model)
set_header model
def paginate(model)
total_count model
return model.limit(limit).offset(offset) if model.respond_to?('limit')
return model[offset..limit]
model[offset..limit]
end
private
def limit
return 50 if params[:limit].blank?
return 12 if params[:limit].blank?
params[:limit].to_i
end
......@@ -19,8 +19,7 @@ module Paginator
params[:offset].to_i
end
def set_header(model)
def total_count(model)
headers['X-Total-Count'] = model.count
end
end
......@@ -13,7 +13,7 @@ class V1::LearningObjectsController < ApplicationController
before_action :authorize!, except: [:create, :tagging, :untagging]
def index
learning_objects = paginate LearningObject.includes(:tags, :publisher, :language, :license)
learning_objects = paginate LearningObject.includes(:tags, :publisher, :language, :license, :subjects, :educational_stages, :reviews)
serializer = params[:obaa].nil? ? LearningObjectSerializer : LearningObjectObaaSerializer
render json: learning_objects, each_serializer: serializer
end
......
class LearningObjectSerializer < ActiveModel::Serializer
cache key: 'learning_object', expires_in: 4.hours
def default_location
object.default_attachment.try(:retrieve_url)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment