Skip to content

Commit

Permalink
update delete zombie mapping counts to check also submission deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 3, 2024
1 parent 955167b commit c1b5051
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 88 deletions.
33 changes: 12 additions & 21 deletions lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def mapping_counts(enable_debug = false, logger = nil, reload_cache = false, arr
exter_total += v
end
counts[external_uri.to_s] = exter_total
if enable_debug
logger.info("Time for External Mappings took #{Time.now - t0} sec. records #{exter_total}")
end
logger.info("Time for External Mappings took #{Time.now - t0} sec. records #{exter_total}") if enable_debug
LinkedData.settings.interportal_hash ||= {}
# Counting for Interportal mappings
LinkedData.settings.interportal_hash.each_key do |acro|
Expand Down Expand Up @@ -93,8 +91,8 @@ def create_mapping_count_totals_for_ontologies(logger, arr_acronyms)
persistent_counts[m.ontologies.first] = m
end

ontologies = LinkedData::Models::Ontology.where.include(:acronym).all.map(&:acronym)
delete_zombie_mapping_count(persistent_counts.values, ontologies)
latest = self.retrieve_latest_submissions(options = { acronyms: arr_acronyms })
delete_zombie_mapping_count(persistent_counts.values, latest.values.compact.map { |sub| sub.ontology.acronym })

num_counts = new_counts.keys.length
ctr = 0
Expand Down Expand Up @@ -160,8 +158,6 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms)
# temp_dir = '/Users/mdorf/Downloads/test/'
# temp_file_path = File.join(File.dirname(file_path), "test.ttl")
# fsave = File.open(temp_file_path, "a")
ontologies = LinkedData::Models::Ontology.where.include(:acronym).all.map(&:acronym)

latest_submissions.each do |acr, sub|
self.handle_triple_store_downtime(logger) if Goo.backend_4s?
new_counts = nil
Expand All @@ -175,14 +171,11 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms)
LinkedData::Models::MappingCount.where(pair_count: true).and(ontologies: acr)
.include(:ontologies, :count).all.each do |m|
other = m.ontologies.first

if other == acr
other = m.ontologies[1]
end
other = m.ontologies.last if other == acr
persistent_counts[other] = m
end

delete_zombie_mapping_count(persistent_counts.values, ontologies)
delete_zombie_mapping_count(persistent_counts.values, latest_submissions.values.compact.map { |s| s.ontology.acronym })

num_counts = new_counts.keys.length
logger.info("Ontology: #{acr}. #{num_counts} mapping pair counts to record...")
Expand All @@ -198,7 +191,7 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms)
if new_count.zero?
inst.delete

Check warning on line 192 in lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb#L192

Added line #L192 was not covered by tests
elsif new_count != inst.count
inst.bring_remaining
inst.bring_remaining if inst.persistent?
inst.pair_count = true
inst.count = new_count

Expand All @@ -216,13 +209,12 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms)
end
end
else
next unless ontologies.include?(other)
next unless new_counts.key?(other)

m = LinkedData::Models::MappingCount.new
m.count = new_count
m.ontologies = [acr, other]
m.pair_count = true
puts "creating mapping count #{m.ontologies}"
begin
if m.valid?
m.save()
Expand Down Expand Up @@ -254,17 +246,16 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms)

private

def delete_zombie_mapping_count(mappings_count, ontologies)
def delete_zombie_mapping_count(existent_counts, submissions_ready)
special_mappings = ["http://data.bioontology.org/metadata/ExternalMappings",
"http://data.bioontology.org/metadata/InterportalMappings/agroportal",
"http://data.bioontology.org/metadata/InterportalMappings/ncbo",
"http://data.bioontology.org/metadata/InterportalMappings/sifr"]

mappings_count.each do |mapping|
next mapping if mapping.ontologies.all? { |x| ontologies.include?(x) }
next mapping if mapping.ontologies.size == 1 && !(mapping.ontologies & special_mappings).empty?

next mapping unless mapping.persistent?
existent_counts.each do |mapping|
next if mapping.ontologies.size == 1 && !(mapping.ontologies & special_mappings).empty?
next if mapping.ontologies.all? { |x| submissions_ready.include?(x) }
next unless mapping.persistent?

mapping.delete
end
Expand Down
9 changes: 8 additions & 1 deletion lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ def bring_remaining
def self.segment_instance(sub)
sub.bring(:ontology) unless sub.loaded_attributes.include?(:ontology)
sub.ontology.bring(:acronym) unless sub.ontology.loaded_attributes.include?(:acronym)
[sub.ontology.acronym] rescue []
begin
[sub.ontology.acronym]
rescue
[]

Check warning on line 271 in lib/ontologies_linked_data/models/ontology_submission.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/models/ontology_submission.rb#L271

Added line #L271 was not covered by tests
end
end

def self.submission_id_generator(ss)
Expand Down Expand Up @@ -424,6 +428,9 @@ def data_folder
end

def zipped?(full_file_path = uploadFilePath)
return false if full_file_path.nil?
return false unless File.exist?(full_file_path)

LinkedData::Utils::FileHelpers.zip?(full_file_path) || LinkedData::Utils::FileHelpers.gzip?(full_file_path)
end

Expand Down
4 changes: 3 additions & 1 deletion test/http_cache/test_http_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_cache_segment_proper_setup
end

def test_cache_segment_invalidate
create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: true)
classes = LinkedData::Models::Class.where.include(:prefLabel).in(@@ontology.latest_submission).page(1, 100).to_a
classes.each {|c| c.cache_write}
last_modified_values = classes.map {|c| c.last_modified}
Expand All @@ -67,6 +68,7 @@ def test_cache_segment_invalidate
end

def test_cache_segment_invalidate_when_member_invalidates
create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: true)
classes = LinkedData::Models::Class.where.include(:prefLabel).in(@@ontology.latest_submission).page(1, 100).to_a
classes.each {|c| c.cache_write}
last_modified_values = classes.map {|c| c.last_modified}
Expand Down Expand Up @@ -137,4 +139,4 @@ def test_cache_invalidate_all
assert_equal [], LinkedData::HTTPCache.keys_for_invalidate_all
end

end
end
Loading

0 comments on commit c1b5051

Please sign in to comment.