diff --git a/app/controllers/concerns/paginator.rb b/app/controllers/concerns/paginator.rb index 38dda601b1351ee381bad672799ccaec8eb90aa5..af015ff08cf386bb3a8a6fff7f96e8a8567cfe90 100644 --- a/app/controllers/concerns/paginator.rb +++ b/app/controllers/concerns/paginator.rb @@ -38,7 +38,7 @@ module Paginator def offset return params[:offset].to_i if !params[:offset].blank? - return params[:page].to_i*params[:results_per_page].to_i if !params[:page].blank? && !params[:results_per_page].blank? + return params[:page].to_i*limit if !params[:page].blank? return 0 end diff --git a/app/controllers/concerns/reviewable_controller.rb b/app/controllers/concerns/reviewable_controller.rb index 4b3eabe810f93288bb5fd4ba2a1cd632083606a4..b6b794847385feba8a1ace067de17bfff8991a69 100644 --- a/app/controllers/concerns/reviewable_controller.rb +++ b/app/controllers/concerns/reviewable_controller.rb @@ -29,7 +29,7 @@ module ReviewableController # GET /v1/collections/1/reviews def index - render json: Review.where(reviewable: reviewable) + render json: paginate(Review.where(reviewable: reviewable)), each_serializer: ReviewSerializer end # GET /v1/collections/1/reviews/1 diff --git a/app/controllers/v1/reviews_controller.rb b/app/controllers/v1/reviews_controller.rb index 9f8fe1559d3f94543fcbde7bfbe39643025cb552..2ca13cecf276ac39dd13cc3934bdd0e36b12b054 100644 --- a/app/controllers/v1/reviews_controller.rb +++ b/app/controllers/v1/reviews_controller.rb @@ -20,13 +20,14 @@ class V1::ReviewsController < ApplicationController include ::DeletedObjectsController include ::ResourceModel + include ::Paginator before_action :set_review, only: [:show, :destroy, :rate, :update] before_action :authenticate_user!, only: [:create, :rate, :destroy, :update] # GET /v1/collections/1/reviews def index - render json: reviewable.reviews, each_serializer: ReviewSerializer + render json: paginate(reviewable.reviews), each_serializer: ReviewSerializer end # GET /v1/collections/1/reviews/1 diff --git a/lib/tasks/attachment_maintaining_service.rake b/lib/tasks/attachment_maintaining_service.rake index dfa314e10a8cfd5a59d1316532eeac70c8dc8d74..41e24ccf939eb862225b00a908a7bc48b27f2b20 100644 --- a/lib/tasks/attachment_maintaining_service.rake +++ b/lib/tasks/attachment_maintaining_service.rake @@ -38,6 +38,64 @@ require 'fileutils' end end + task check_links: :environment do + OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE + start = 1 + finish = 999 + batch_size = 1000 + last_id = LearningObject::Attachment.count > 0 ? LearningObject::Attachment.last.id : 0 + + loop do + begin + p "start: #{start}, finish: #{finish}" + LearningObject::Attachment.find_each(start: start, finish: finish) do |att| + att_url = att.retrieve_url + if att_url.blank? + p "-----------------------------------------------------" + p "Retrieve URL nil" + p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil? + p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}" + else + begin + URI.parse(att_url) + rescue URI::InvalidURIError + p "-----------------------------------------------------" + p "Invalid URI: #{att_url}" + p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil? + p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}" + next + end + uri = URI(att_url) + response = Net::HTTP.get_response(uri) + if !response.kind_of? Net::HTTPSuccess + p "-----------------------------------------------------" + p "Response != 200: #{response.inspect}" + p "Link: #{att_url}" + p "LearningObject id: #{att.learning_object.id}" if !att.learning_object.nil? + p "Attachment id: #{att.id}, id_dspace: #{att.id_dspace}" + end + end + end + rescue Exception => e + #logger.warn 'Database error, going to sleep' + p 'Database error, going to sleep' + #logger.error e + p e + p e.class + p e.message + ActiveRecord::Base.clear_active_connections! + # Sleeps for a while to wait database's recovery + sleep(60.seconds) + # Goes to next iteration to retry + next + else + start += batch_size - 1 + finish += batch_size + break if start >= last_id + end + end + end + private def dir_size(dir)