Skip to content

Commit

Permalink
benchmarks for prefixes. #224
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 8, 2019
1 parent b507ef2 commit 95a28b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'benchmark'

class ClientsController < ApplicationController
include Countable

Expand Down
3 changes: 3 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def index
else nil
end

response = nil

if params[:id].present?
logger.info "[Benchmark] find_by_id " + Benchmark.ms {
response = Doi.find_by_id(params[:id])
Expand Down Expand Up @@ -90,6 +92,7 @@ def index
total = sample_dois.length
total_pages = 1
else
results = nil
logger.info "[Benchmark] results " + Benchmark.ms {
results = response.results.results
}.to_s + " ms"
Expand Down
21 changes: 15 additions & 6 deletions app/controllers/prefixes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'benchmark'

class PrefixesController < ApplicationController

before_action :set_prefix, only: [:show, :update, :destroy]
before_action :authenticate_user!
before_action :set_include
Expand Down Expand Up @@ -137,14 +138,22 @@ def update
end

def totals
logger = Logger.new(STDOUT)

page = { size: 0, number: 1}
response = Doi.query("", client_id: params[:client_id],page: page, totals_agg: true)
response = nil
logger.info "[Benchmark] prefixes totals " + Benchmark.ms {
response = Doi.query("", client_id: params[:client_id],page: page, totals_agg: true)
}.to_s + " ms"
total = response.results.total

registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil

render json: registrant, status: :ok

registrant = nil
logger.info "[Benchmark] prefixes prefixes_totals " + Benchmark.ms {
registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil
}.to_s + " ms"
logger.info "[Benchmark] clients render " + Benchmark.ms {
render json: registrant, status: :ok
}.to_s + " ms"
end

def destroy
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'benchmark'

class ProvidersController < ApplicationController
include Countable

Expand Down

0 comments on commit 95a28b5

Please sign in to comment.