Skip to content

Commit

Permalink
Merge branch 'development' into feature/add-rails-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 5, 2024
2 parents 41fbf82 + 15ad7d4 commit 0f7f15c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/ontologies_api_client/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def config(&block)

def config_connection(options = {})
return if @settings_run_connection
store = options[:cache_store] || ActiveSupport::Cache::RedisCacheStore.new
@settings.conn = faraday_connection(@settings.rest_url, @settings.apikey, store)
store = options[:cache_store] || ActiveSupport::Cache::MemoryStore.new
@settings.conn = faraday_connection(@settings.rest_url, @settings.apikey, store, current_portal: true)
@settings.federated_conn = @settings.federated_portals.map do |portal_name, portal_info|
[portal_name, faraday_connection(portal_info[:api], portal_info[:apikey], store)]
end.to_h
Expand All @@ -51,21 +51,24 @@ def connection_configured?
end

private
def faraday_connection(url, apikey, store)
def faraday_connection(url, apikey, store, current_portal: false)
Faraday.new(url.to_s.chomp('/')) do |faraday|

if @settings.enable_long_request_log
require_relative 'middleware/faraday-long-requests'
faraday.use :long_requests
end

require_relative 'middleware/faraday-user-apikey'
faraday.use :user_apikey
if current_portal
require_relative 'middleware/faraday-user-apikey'
faraday.use :user_apikey

require_relative 'middleware/faraday-slices'
faraday.use :ncbo_slices
require_relative 'middleware/faraday-slices'
faraday.use :ncbo_slices

require_relative 'middleware/faraday-last-updated'
faraday.use :last_updated
require_relative 'middleware/faraday-last-updated'
faraday.use :last_updated
end

if @settings.cache
begin
Expand Down
4 changes: 3 additions & 1 deletion lib/ontologies_api_client/request_federation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def self.included(base)
module ClassMethods
def federated_get(params = {}, &link)
portals = request_portals(params)
main_thread_locals = Thread.current.keys.map { |key| [key, Thread.current[key]] }.to_h

connections = Parallel.map(portals, in_threads: portals.size) do |conn|
main_thread_locals.each { |key, value| Thread.current[key] = value }
begin
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), params, connection: conn)
rescue StandardError => e
rescue Exception => e
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
end
end
Expand Down

0 comments on commit 0f7f15c

Please sign in to comment.