Skip to content

Commit

Permalink
Fix: optimize fetching all agents usages query by batch loading them (#…
Browse files Browse the repository at this point in the history
…57)

* add agent usage attribute tests

* optimize fetching all agents usages query by batch loading them
  • Loading branch information
syphax-bouazzouni authored Nov 8, 2023
1 parent 01cdda4 commit d8eb63a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: b49ad10781e83360a5dd1968972c4048592eefda
revision: 7d16b7b1ecc4da8bfd93db2a106737b06d84d6ff
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -108,7 +108,7 @@ GEM
airbrussh (1.5.0)
sshkit (>= 1.6.1, != 1.7.0)
backports (3.24.1)
base64 (0.1.1)
base64 (0.2.0)
bcrypt (3.1.19)
bcrypt_pbkdf (1.1.0)
bigdecimal (1.4.2)
Expand All @@ -131,7 +131,7 @@ GEM
rexml
cube-ruby (0.0.3)
dante (0.2.0)
date (3.3.3)
date (3.3.4)
declarative (0.0.20)
docile (1.4.0)
domain_name (0.5.20190701)
Expand Down Expand Up @@ -196,8 +196,8 @@ GEM
json_pure (2.6.3)
jwt (2.7.1)
kgio (2.11.4)
libxml-ruby (4.1.1)
logger (1.5.3)
libxml-ruby (4.1.2)
logger (1.6.0)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.8.1)
Expand All @@ -217,12 +217,12 @@ GEM
multi_json (1.15.0)
multipart-post (2.3.0)
net-http-persistent (2.9.4)
net-imap (0.4.3)
net-imap (0.4.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
Expand Down Expand Up @@ -327,7 +327,7 @@ GEM
systemu (2.6.5)
temple (0.10.3)
tilt (2.3.0)
timeout (0.4.0)
timeout (0.4.1)
trailblazer-option (0.1.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down
5 changes: 5 additions & 0 deletions controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class AgentsController < ApplicationController
else
agents = query.to_a
end

if includes_param.include?(:all) || includes_param.include?(:usages)
LinkedData::Models::Agent.load_agents_usages(agents)
end

reply agents
end

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/test_agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def teardown
end

def test_all_agents
get '/agents?display=all'
get '/agents?display=all&page=1'
assert last_response.ok?

created_agents = MultiJson.load(last_response.body)
@agents.each do |agent|
created_agent = created_agents.select{|x| x["name"].eql?(agent[:name])}.first
created_agent = created_agents["collection"].select{|x| x["name"].eql?(agent[:name])}.first
refute_nil created_agent
refute_nil created_agent["usages"]
assert_equal agent[:name], created_agent["name"]
Expand Down

0 comments on commit d8eb63a

Please sign in to comment.