diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb index dbf0b7536a3d7afed85fa92735edc242fe7ecd69..143a9e9108cbb1ea93c2b1ccc1a74795090c79d6 100644 --- a/app/repositories/orient_db/learning_object_repository.rb +++ b/app/repositories/orient_db/learning_object_repository.rb @@ -137,8 +137,16 @@ module OrientDb end def all_by_score_from_offset_to_limit(offset, limit) - objects_hash = connection.query "SELECT FROM LearningObject ORDER BY score DESC LIMIT #{limit} SKIP #{offset}", limit: limit - build_objects(objects_hash) || [] + return [] if offset.blank? || limit.blank? + + # expensive query + key = 'learning_objects/all/score/' + offset.to_s + '/' + limit.to_s + objects_hash = Rails.cache.fetch(key, expires_in: 6.hours) do + objects = connection.query "SELECT FROM LearningObject ORDER BY score DESC LIMIT #{limit} SKIP #{offset}", limit: limit + objects.map { |o| { 'rid' => o['@rid'] } } + end + + LearningObjectBuilder.build(objects_hash) end def get_subjects(learning_object)