Commit b5809eab by John Doe

improved data loading performance

parent 750579a7
...@@ -73,8 +73,8 @@ class DbAdapter ...@@ -73,8 +73,8 @@ class DbAdapter
path: entry[0], path: entry[0],
attributes: { attributes: {
data_type: entry[1], data_type: entry[1],
start_time: entry[2] || 0, start_time: entry[2],
end_time: entry[3] || 0, end_time: entry[3],
total_rows: entry[4], total_rows: entry[4],
total_time: entry[5] total_time: entry[5]
}.merge(metadata), }.merge(metadata),
......
...@@ -59,10 +59,8 @@ class LoadElementData ...@@ -59,10 +59,8 @@ class LoadElementData
req_streams.each do |stream| req_streams.each do |stream|
adapter = DbAdapter.new(stream.db.url) adapter = DbAdapter.new(stream.db.url)
data_service = LoadStreamData.new(adapter) data_service = LoadStreamData.new(adapter)
time = Benchmark.measure do
data_service.run(stream, @start_time, @end_time,elements.to_a) data_service.run(stream, @start_time, @end_time,elements.to_a)
end
puts "------ DataService #{time}"
if data_service.success? if data_service.success?
combined_data.concat(data_service.data) combined_data.concat(data_service.data)
else else
......
...@@ -64,6 +64,7 @@ class LoadStreamData ...@@ -64,6 +64,7 @@ class LoadStreamData
@decimation_factor = plottable_decim.level @decimation_factor = plottable_decim.level
path = __build_path(db_stream, plottable_decim.level) path = __build_path(db_stream, plottable_decim.level)
resp = @db_adapter.get_data(path, start_time, end_time) resp = @db_adapter.get_data(path, start_time, end_time)
if resp.nil? if resp.nil?
add_error("cannot get data for [#{path}] @ #{@db_adapter.url}") add_error("cannot get data for [#{path}] @ #{@db_adapter.url}")
return self return self
...@@ -77,11 +78,9 @@ class LoadStreamData ...@@ -77,11 +78,9 @@ class LoadStreamData
decimateable_elements = decimateable_elements =
elements.select{|e| %w(continuous discrete).include? e.display_type} elements.select{|e| %w(continuous discrete).include? e.display_type}
interval_elements = elements.select{|e| e.display_type=='event'} interval_elements = elements.select{|e| e.display_type=='event'}
time = Benchmark.measure do
@data = __build_decimated_data(decimateable_elements, resp) + @data = __build_decimated_data(decimateable_elements, resp) +
__build_intervals_from_decimated_data(interval_elements, resp) __build_intervals_from_decimated_data(interval_elements, resp)
end
puts "---- [LoadStreamData] Build Dataset #{time}"
end end
self self
end end
......
...@@ -19,7 +19,7 @@ Rails.application.routes.draw do ...@@ -19,7 +19,7 @@ Rails.application.routes.draw do
end end
resources :db_elements, only: [:index] do resources :db_elements, only: [:index] do
collection do collection do
post 'data' get 'data'
end end
end end
......
...@@ -4,7 +4,7 @@ require 'rails_helper' ...@@ -4,7 +4,7 @@ require 'rails_helper'
RSpec.describe DbElementsController, type: :request do RSpec.describe DbElementsController, type: :request do
let(:user1) { create(:user, first_name: 'John') } let(:user1) { create(:user, first_name: 'John') }
let(:user2) { create(:user, first_name: 'Sam') } let(:user2) { create(:user, first_name: 'Sam') }
describe 'POST #data' do describe 'GET #data' do
# retrieve data for elements listed by array of ids # retrieve data for elements listed by array of ids
context 'with authenticated user' do context 'with authenticated user' do
before do before do
...@@ -31,7 +31,7 @@ RSpec.describe DbElementsController, type: :request do ...@@ -31,7 +31,7 @@ RSpec.describe DbElementsController, type: :request do
allow(LoadElementData).to receive(:new).and_return(@mock_service) allow(LoadElementData).to receive(:new).and_return(@mock_service)
@auth_headers = user1.create_new_auth_token @auth_headers = user1.create_new_auth_token
post '/db_elements/data.json', get '/db_elements/data.json',
params: { elements: [@elem1.id, @elem2.id].to_json, params: { elements: [@elem1.id, @elem2.id].to_json,
start_time: 0, end_time: 100, redux_json: 'new home view' }, start_time: 0, end_time: 100, redux_json: 'new home view' },
headers: @auth_headers headers: @auth_headers
...@@ -44,7 +44,7 @@ RSpec.describe DbElementsController, type: :request do ...@@ -44,7 +44,7 @@ RSpec.describe DbElementsController, type: :request do
end end
it 'returns error if time bounds are invalid' do it 'returns error if time bounds are invalid' do
@auth_headers = user1.create_new_auth_token @auth_headers = user1.create_new_auth_token
post '/db_elements/data.json', get '/db_elements/data.json',
params: { elements: [@elem1.id, @elem2.id].to_json, params: { elements: [@elem1.id, @elem2.id].to_json,
start_time: 100, end_time: 0 }, start_time: 100, end_time: 0 },
headers: @auth_headers headers: @auth_headers
...@@ -59,7 +59,7 @@ RSpec.describe DbElementsController, type: :request do ...@@ -59,7 +59,7 @@ RSpec.describe DbElementsController, type: :request do
stream2.db_elements << @elem3 stream2.db_elements << @elem3
@auth_headers = user1.create_new_auth_token @auth_headers = user1.create_new_auth_token
post '/db_elements/data.json', get '/db_elements/data.json',
params: { elements: [@elem1.id, @elem3.id].to_json, params: { elements: [@elem1.id, @elem3.id].to_json,
start_time: 100, end_time: 0 }, start_time: 100, end_time: 0 },
headers: @auth_headers headers: @auth_headers
...@@ -68,7 +68,7 @@ RSpec.describe DbElementsController, type: :request do ...@@ -68,7 +68,7 @@ RSpec.describe DbElementsController, type: :request do
end end
context 'without sign-in' do context 'without sign-in' do
it 'returns unauthorized' do it 'returns unauthorized' do
post '/db_elements/data.json' get '/db_elements/data.json'
expect(response).to have_http_status(:unauthorized) expect(response).to have_http_status(:unauthorized)
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment