Skip to content

Commit

Permalink
fix agent load usages sparql query taking too much time
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 16, 2023
1 parent 1af13e4 commit e128d44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
28 changes: 4 additions & 24 deletions lib/ontologies_linked_data/models/agents/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,10 @@ class Agent < LinkedData::Models::Base
access_control_load :creator


def self.load_agents_usages(agents = [])
is_a = RDF::URI.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
q = Goo.sparql_query_client.select(:id, :property, :agent, :status).distinct
.from(LinkedData::Models::OntologySubmission.uri_type)
.where(
[:id,
is_a,
LinkedData::Models::OntologySubmission.uri_type
],
[:id,
LinkedData::Models::OntologySubmission.attribute_uri(:submissionStatus),
:status
]
)


q = q.optional([:agent, is_a, LinkedData::Models::Agent.uri_type])
q = q.optional([:id, :property, :agent])

ready_submission_filter = "?status = <#{RDF::URI.new(LinkedData::Models::SubmissionStatus.id_prefix + 'RDF')}> || ?status = <#{RDF::URI.new(LinkedData::Models::SubmissionStatus.id_prefix + 'UPLOADED')}>"
q.filter(ready_submission_filter)


q.filter(agents.map{|agent| "?agent = <#{agent.id}>"}.join(' || ')) unless agents.empty?
def self.load_agents_usages(agents = [], agent_attributes = OntologySubmission.agents_attr_uris)
q = Goo.sparql_query_client.select(:id, :property, :agent, :status).distinct.from(LinkedData::Models::OntologySubmission.uri_type).where([:id,LinkedData::Models::OntologySubmission.attribute_uri(:submissionStatus),:status], [:id, :property, :agent])
q = q.filter("?status = <#{RDF::URI.new(LinkedData::Models::SubmissionStatus.id_prefix + 'RDF')}> || ?status = <#{RDF::URI.new(LinkedData::Models::SubmissionStatus.id_prefix + 'UPLOADED')}>")
q = q.filter(agent_attributes.map{|attr| "?property = <#{attr}>"}.join(' || '))

data = q.each_solution.group_by{|x| x[:agent]}

Expand Down
3 changes: 3 additions & 0 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ def synchronize(&block)
@mutex.synchronize(&block)
end

def self.agents_attr_uris
agents_attrs.map{ |x| self.attribute_uri(x) }
end

def self.ontology_link(m)
ontology_link = ""
Expand Down

0 comments on commit e128d44

Please sign in to comment.