From 5bf6a05862e2a36ad7fc1d16b96b0961fee900c5 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Fri, 15 Sep 2023 02:38:54 +0200 Subject: [PATCH] use retrieve_submissions helper in the :acronym/submissions endpoint --- .../ontology_submissions_controller.rb | 20 ++++++---------- helpers/application_helper.rb | 2 -- helpers/submission_helper.rb | 23 +++++-------------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/controllers/ontology_submissions_controller.rb b/controllers/ontology_submissions_controller.rb index d88e2f43..5fd5218f 100644 --- a/controllers/ontology_submissions_controller.rb +++ b/controllers/ontology_submissions_controller.rb @@ -29,19 +29,13 @@ class OntologySubmissionsController < ApplicationController error 422, "Ontology #{params["acronym"]} does not exist" unless ont check_last_modified_segment(LinkedData::Models::OntologySubmission, [ont.acronym]) check_access(ont) - 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], :metrics =>[:classes, :individuals, :properties]) - - 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 + 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 84c26497..cde04a34 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -359,8 +359,6 @@ def retrieve_latest_submissions(options = {}) latest_submissions = page? ? submissions : {} # latest_submission doest not work with pagination submissions.each do |sub| - # To retrieve all metadata, but slow when a lot of ontologies - sub.bring_remaining if includes_param.first == :all unless page? next if include_ready?(options) && !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