From 5afb9079d880705668becb69aa17be492de00de7 Mon Sep 17 00:00:00 2001 From: Syphax Date: Sat, 5 Oct 2024 12:26:39 +0200 Subject: [PATCH] save as a custom event the API calls --- lib/ontologies_api_client/http.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ontologies_api_client/http.rb b/lib/ontologies_api_client/http.rb index ebd8750..0fa3297 100644 --- a/lib/ontologies_api_client/http.rb +++ b/lib/ontologies_api_client/http.rb @@ -4,6 +4,7 @@ require 'ostruct' require 'benchmark' require 'active_support/cache' +require 'rails_performance' ## # This monkeypatch makes OpenStruct act like Struct objects class OpenStruct @@ -69,14 +70,17 @@ def self.get(path, params = {}, options = {}) begin response = nil time = Benchmark.realtime do - response = connection.get do |req| - req.url path - req.params = params.dup - req.options[:timeout] = 60 - req.headers.merge(headers) - req.headers[:invalidate_cache] = invalidate_cache + RailsPerformance.measure("Getting: #{path} with #{params} - cache: #{response.headers["X-Rack-Cache"]}", "API Call #{path}") do + response = connection.get do |req| + req.url path + req.params = params.dup + req.options[:timeout] = 60 + req.headers.merge(headers) + req.headers[:invalidate_cache] = invalidate_cache + end end end + puts "Getting: #{path} with #{params} (t: #{time}s - cache: #{response.headers["X-Rack-Cache"]})" if $DEBUG_API_CLIENT rescue Exception => e params = Faraday::Utils.build_query(params)