From a261b249788873b56f0fa21f36656184d18d0078 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 19 Oct 2023 11:09:36 +0200 Subject: [PATCH] use retrieve_submissions helper in the :acronym/submissions endpoint --- .../ontology_submissions_controller.rb | 21 +++++++---------- helpers/application_helper.rb | 8 ++++--- helpers/submission_helper.rb | 23 +++++-------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/controllers/ontology_submissions_controller.rb b/controllers/ontology_submissions_controller.rb index 8b4cf4f1..86c06f2f 100644 --- a/controllers/ontology_submissions_controller.rb +++ b/controllers/ontology_submissions_controller.rb @@ -22,19 +22,14 @@ class OntologySubmissionsController < ApplicationController ont = Ontology.find(params["acronym"]).include(:acronym).first error 422, "Ontology #{params["acronym"]} does not exist" unless ont check_last_modified_segment(LinkedData::Models::OntologySubmission, [ont.acronym]) - if includes_param.first == :all - # When asking to display all metadata, we are using bring_remaining which is more performant than including all metadata (remove this when the query to get metadata will be fixed) - ont.bring(submissions: [:released, :creationDate, :status, :submissionId, - {:contact=>[:name, :email], :ontology=>[:administeredBy, :acronym, :name, :summaryOnly, :ontologyType, :viewingRestriction, :acl, :group, :hasDomain, :views, :viewOf, :flat], - :submissionStatus=>[:code], :hasOntologyLanguage=>[:acronym]}, :submissionStatus]) - - ont.submissions.each do |sub| - sub.bring_remaining - end - else - ont.bring(submissions: OntologySubmission.goo_attrs_to_load(includes_param)) - end - reply ont.submissions.sort {|a,b| b.submissionId.to_i <=> a.submissionId.to_i } # descending order of submissionId + check_access(ont) + options = { + also_include_views: params["also_include_views"], + status: (params["include_status"] || "ANY") + } + subs = retrieve_submissions(options) + + reply subs.sort {|a,b| b.submissionId.to_i <=> a.submissionId.to_i } # descending order of submissionId end ## diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 10871498..dbd50106 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -382,9 +382,11 @@ def retrieve_latest_submissions(options = {}) # Figure out latest parsed submissions using all submissions latest_submissions = {} submissions.each do |sub| - # To retrieve all metadata, but slow when a lot of ontologies - if includes_param.first == :all - sub.bring_remaining + unless page? + next if include_ready?(options) && !sub.ready? + next if sub.ontology.nil? + latest_submissions[sub.ontology.acronym] ||= sub + latest_submissions[sub.ontology.acronym] = sub if sub.submissionId.to_i > latest_submissions[sub.ontology.acronym].submissionId.to_i end next if include_ready && !sub.ready? next if sub.ontology.nil? diff --git a/helpers/submission_helper.rb b/helpers/submission_helper.rb index c23bcdaa..b9a960b9 100644 --- a/helpers/submission_helper.rb +++ b/helpers/submission_helper.rb @@ -19,6 +19,7 @@ def submission_include_params def retrieve_submissions(options) status = (options[:status] || "RDF").to_s.upcase status = "RDF" if status.eql?("READY") + ontology_acronym = options[:ontology] any = status.eql?("ANY") include_views = options[:also_include_views] || false includes, page, size, order_by, _ = settings_params(LinkedData::Models::OntologySubmission) @@ -32,28 +33,16 @@ def retrieve_submissions(options) submissions_query = submissions_query.where({submissionStatus: [ code: status]}) end + + submissions_query.where(ontology: [acronym: ontology_acronym]) if ontology_acronym + + submissions_query = apply_filters(submissions_query) submissions_query = submissions_query.filter(Goo::Filter.new(ontology: [:viewOf]).unbound) unless include_views submissions_query = submissions_query.filter(filter) if filter? - # When asking to display all metadata, we are using bring_remaining on each submission. Slower but best way to retrieve all attrs - if includes_param.first == :all - includes = [:submissionId, {:contact=>[:name, :email], - :ontology=>[:administeredBy, :acronym, :name, :summaryOnly, :ontologyType, :viewingRestriction, :acl, - :group, :hasDomain, :views, :viewOf, :flat, :notes, :reviews, :projects], - :submissionStatus=>[:code], :hasOntologyLanguage=>[:acronym], :metrics =>[:classes, :individuals, :properties]}, - :submissionStatus] - else - if includes.find{|v| v.is_a?(Hash) && v.keys.include?(:ontology)} - includes << {:ontology=>[:administeredBy, :acronym, :name, :viewingRestriction, :group, :hasDomain,:notes, :reviews, :projects,:acl, :viewOf]} - end - - if includes.find{|v| v.is_a?(Hash) && v.keys.include?(:contact)} - includes << {:contact=>[:name, :email]} - end - end - submissions = submissions_query.include(includes) + submissions = submissions_query.include(submission_include_params) if page? submissions.page(page, size).all else