Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GIT

GIT
remote: https://github.com/ncbo/goo.git
revision: cc806c845c79b707e7a10f44e4959caa15939b8b
revision: 752fb6b3fe2ec0ba9417397f3283baeac7a9abfc
branch: development
specs:
goo (0.0.2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ module Models
module SKOS
module RootsFetcher

def skos_roots(concept_schemes, page, paged, pagesize)
classes = []
def skos_root_ids(concept_schemes, page, paged, pagesize)
class_ids, count = roots_by_has_top_concept(concept_schemes, page, paged, pagesize)

class_ids, count = roots_by_top_concept_of(concept_schemes, page, paged, pagesize) if class_ids.empty?

class_ids.each do |id|
classes << LinkedData::Models::Class.find(id).in(self).disable_rules.first
end

classes = Goo::Base::Page.new(page, pagesize, count, classes) if paged
classes
[class_ids, count]
end

private
Expand Down
19 changes: 15 additions & 4 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,11 @@ def roots(extra_include = [], page = nil, pagesize = nil, concept_schemes: [], c

skos = self.skos?
classes = []
class_ids = []
root_count = 0

if skos
classes = skos_roots(concept_schemes, page, paged, pagesize)
class_ids, root_count = skos_root_ids(concept_schemes, page, paged, pagesize)
extra_include += LinkedData::Models::Class.concept_is_in_attributes
else
self.ontology.bring(:flat)
Expand Down Expand Up @@ -744,7 +746,12 @@ def roots(extra_include = [], page = nil, pagesize = nil, concept_schemes: [], c
end
end

where = LinkedData::Models::Class.in(self).models(classes).include(:prefLabel, :definition, :synonym, :obsolete)
where = if skos
LinkedData::Models::Class.in(self).ids(class_ids) unless class_ids.empty?
else
LinkedData::Models::Class.in(self).models(classes)
end
where.include(:prefLabel, :definition, :synonym, :obsolete) if where

if extra_include
%i[prefLabel definition synonym obsolete childrenCount].each do |x|
Expand All @@ -767,9 +774,13 @@ def roots(extra_include = [], page = nil, pagesize = nil, concept_schemes: [], c
load_children = [:children]
end

where.include(extra_include) if extra_include.length > 0
where.include(extra_include) if where && extra_include.length > 0
end
where.all
if where
loaded_classes = where.all
classes = loaded_classes if skos
end
classes = Goo::Base::Page.new(page, pagesize, root_count, classes) if skos && paged

LinkedData::Models::Class.partially_load_children(classes, 99, self) if load_children.length > 0

Expand Down
35 changes: 34 additions & 1 deletion test/models/test_skos_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ def test_roots_of_multiple_scheme
'http://www.ebi.ac.uk/efo/EFO_0000324'].sort
end

def test_roots_batch_loads_skos_classes
sub = before_suite
concept_schemes = ['http://www.ebi.ac.uk/efo/skos/EFO_GWAS_view_2',
'http://www.ebi.ac.uk/efo/skos/EFO_GWAS_view']

roots = nil
queries = count_sparql_queries do
roots = sub.roots(concept_schemes: concept_schemes)
end

assert_equal 6, roots.length
assert_operator queries, :<=, 3,
"loading #{roots.length} SKOS roots issued #{queries} SPARQL queries -- " \
'looks like per-root class hydration'
end

def test_roots_batch_load_preserves_skos_pagination
sub = before_suite
concept_scheme = 'http://www.ebi.ac.uk/efo/skos/EFO_GWAS_view'

roots = sub.roots([], 1, 2, concept_schemes: [concept_scheme])

assert_instance_of Goo::Base::Page, roots
assert_equal 2, roots.length
assert_equal 2, roots.total_pages
end

def test_roots_with_no_skos_ids_returns_empty
sub = before_suite
roots = sub.roots(concept_schemes: ['http://example.org/missing-scheme'])

assert_empty roots
end

def test_roots_of_scheme_collection
sub = before_suite

Expand Down Expand Up @@ -241,4 +275,3 @@ def test_concept_schemes_query_memoized_per_submission
'submission instance -- per-submission memoization (#302/#303) regressed'
end
end

Loading