Skip to content

Commit

Permalink
use retrieve_submissions helper in the :acronym/submissions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 19, 2023
1 parent f4dc641 commit a261b24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
21 changes: 8 additions & 13 deletions controllers/ontology_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
8 changes: 5 additions & 3 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
23 changes: 6 additions & 17 deletions helpers/submission_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a261b24

Please sign in to comment.