sort filtered musicians by latency order from neo4j
This commit is contained in:
parent
505f2d5592
commit
15bd48ce3b
|
|
@ -144,7 +144,7 @@ function JKPeopleFilter() {
|
|||
|
||||
try {
|
||||
dispatch(loadPrefetched())
|
||||
if(totalPages && _page >= totalPages){
|
||||
if(totalPages && _page > totalPages){
|
||||
return
|
||||
}
|
||||
dispatch(fetchPeople({ data: params, page: _page }));
|
||||
|
|
|
|||
|
|
@ -153,13 +153,13 @@ module JamRuby
|
|||
def do_search(params={}, user_ids)
|
||||
rel = User.musicians.where('users.id <> ?', self.user.id)
|
||||
|
||||
#user_ids parameter is used to track users returned from neo4j user's latency data service. #if this variable is not null means we are calling this method to fiter musicians with neo4j latency data (currently this call only comes from api_search_controller#filter)
|
||||
#user_ids parameter is used to track users returned from neo4j user's latency data service. #if this variable is not null means we are calling this method with neo4j latency data (currently this call only comes from api_search_controller#filter)
|
||||
|
||||
unless user_ids.nil?
|
||||
if user_ids.empty?
|
||||
return User.none # no user_ids have been passed from latency service. which means no results for the latency based filter conditions. So we return an empty result
|
||||
return User.none # no user_ids have been passed from latency service. which means no results for the latency based filter conditions. So we return an empty data set
|
||||
else
|
||||
rel = rel.where(id: user_ids).where('users.id <> ?', self.user.id)
|
||||
rel = rel.where(id: user_ids).where('users.id <> ?', self.user.id).order("array_position(ARRAY[#{user_ids.map { |i| "'#{i}'" }.join(',')}], id::TEXT)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -106,19 +106,17 @@ class ApiSearchController < ApiController
|
|||
|
||||
@latency_data = []
|
||||
begin
|
||||
if latency_good || latency_fair || latency_high
|
||||
#bm = Benchmark.measure do
|
||||
@latency_data = users_latency_data(latency_good, latency_fair, latency_high)
|
||||
#end
|
||||
end
|
||||
|
||||
|
||||
#bm = Benchmark.measure do
|
||||
@latency_data = users_latency_data(latency_good, latency_fair, latency_high)
|
||||
user_ids = @latency_data.map{ |l_data| l_data[:user_id] }
|
||||
#end
|
||||
|
||||
# Bugsnag.notify("search_users_benchmark") do |report|
|
||||
# report.severity = "info"
|
||||
# report.add_tab(:benchmark, benchmark: bm.to_s)
|
||||
# end if Rails.env.production?
|
||||
|
||||
user_ids = @latency_data.map{ |l_data| l_data[:user_id] }
|
||||
|
||||
|
||||
filter_params = {
|
||||
"sort_order"=>"latency",
|
||||
"instruments"=>[],
|
||||
|
|
@ -160,7 +158,6 @@ class ApiSearchController < ApiController
|
|||
|
||||
sobj = MusicianSearch.user_search_filter(current_user)
|
||||
@search = sobj.search_results_page(filter_params, [params[:page].to_i, 1].max, user_ids)
|
||||
#@search = sobj.search_results_page(filter_params, [params[:page].to_i, 1].max)
|
||||
|
||||
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index'
|
||||
|
||||
|
|
|
|||
|
|
@ -51,10 +51,30 @@ describe "Musician Filter API", type: :request do
|
|||
expect(JSON.parse(response.body)["musicians"].size).to eq(7)
|
||||
end
|
||||
|
||||
it "filter all musicians for all latency types" do
|
||||
it "filter musicians when no latency option is selected" do
|
||||
post '/api/filter.json', { latency_good: false, latency_fair: false, latency_high: false }
|
||||
expect(JSON.parse(response.body)["musicians"].size).to eq(7)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]).to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["audio_latency"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["ars_internet_latency"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["ars_total_latency"]).not_to eq(nil)
|
||||
end
|
||||
|
||||
it "filter musicians for all latency options", focus: true do
|
||||
post '/api/filter.json', { latency_good: true, latency_fair: true, latency_high: true }
|
||||
expect(JSON.parse(response.body)["musicians"].size).to eq(6)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["audio_latency"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["ars_internet_latency"]).not_to eq(nil)
|
||||
expect(JSON.parse(response.body)["musicians"][0]["latency_data"]["ars_total_latency"]).not_to eq(nil)
|
||||
|
||||
#sort by latency
|
||||
expect(JSON.parse(response.body)["musicians"][0]["id"]).to eq(user1.id)
|
||||
expect(JSON.parse(response.body)["musicians"][1]["id"]).to eq(user2.id)
|
||||
expect(JSON.parse(response.body)["musicians"][2]["id"]).to eq(user3.id)
|
||||
expect(JSON.parse(response.body)["musicians"][3]["id"]).to eq(user4.id)
|
||||
expect(JSON.parse(response.body)["musicians"][4]["id"]).to eq(user5.id)
|
||||
expect(JSON.parse(response.body)["musicians"][5]["id"]).to eq(user6.id)
|
||||
end
|
||||
|
||||
it "filter GOOD latency users" do
|
||||
|
|
|
|||
Loading…
Reference in New Issue