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

add learning object cache

parent bea73b88
No related branches found
No related tags found
No related merge requests found
......@@ -47,10 +47,10 @@ module OrientDb
# list.each do |learning_object|
# learning_object.inspect <LearningObject model>
# end
def all
learning_objects_hash = connection.query "SELECT FROM LearningObject"
build_objects(learning_objects_hash) || []
end
# def all
# learning_objects_hash = connection.query "SELECT FROM LearningObject"
# build_objects(learning_objects_hash) || []
# end
# Usage:
# learning_object = repository.for(:learning_objects).get_by_dspace_id 123
......@@ -103,24 +103,37 @@ module OrientDb
FROM index:learningobject_search
WHERE key LUCENE '#{qry}'
", limit: 10000
# learning_objects_hash = connection.query "#SELECT @rid.asString() FROM (
# SELECT EXPAND(rid) FROM index:learningobject_search
# WHERE key LUCENE '#{qry}'
# )", limit: 10000
build_objects(learning_objects_hash) || []
end
def build_object(args={})
lo = nil
unless args.nil?
lo = LearningObject.new(:id => args["@rid"],
:name => args["name"],
:description => args["description"],
:thumbnail => args["thumbnail"],
:created_at => args["created_at"],
:id_dspace => args["id_dspace"],
:type => args["type"],
:bitstreams => args["bitstreams"],
:metadata => args["metadata"],
:last_modified => args["last_modified"])
lo.likes = args.has_key?("in_Likes") ? args["in_Likes"].size : 0
lo.views = args.has_key?("in_Views") ? args["in_Views"].size : 0
# cache object when build
cache_key = args["@rid"] + '/' + args["last_modified"]
lo = Rails.cache.fetch(cache_key, expires_in: 12.hours) do
likes = args.has_key?("in_Likes") ? args["in_Likes"].size : 0
views = args.has_key?("in_Views") ? args["in_Views"].size : 0
LearningObject.new(
id: args["@rid"],
name: args["name"],
description: args["description"],
thumbnail: args["thumbnail"],
created_at: args["created_at"],
id_dspace: args["id_dspace"],
type: args["type"],
bitstreams: args["bitstreams"],
metadata: args["metadata"],
last_modified: args["last_modified"],
likes: likes,
views: views
)
end
end
lo
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