* fix bug in connection stats

This commit is contained in:
Seth Call 2015-01-01 21:45:07 -06:00
parent 0f288539cd
commit 5758096f33
2 changed files with 19 additions and 3 deletions

View File

@ -229,11 +229,12 @@ module JamRuby
CLIENT_TYPES.each do |type|
stats[type] = 0
end
Connection.select('count(client_type) AS client_type_count, client_type') do |result|
stats[result['client_type']] = result['client_type_count']
Connection.select('count(client_type) AS client_type_count, client_type').group('client_type').all.each do |result|
stats[result['client_type']] = result['client_type_count'].to_i
end
result = Connection.select('count(id) AS total, count(scoring_timeout) AS scoring_timeout_count, count(music_session_id) AS in_session, count(as_musician) AS musicians, count(udp_reachable) AS udp_reachable_count, count(is_network_testing) AS is_network_testing_count').first
result = Connection.select('count(id) AS total, count(CASE WHEN scoring_timeout > NOW() THEN 1 ELSE null END) AS scoring_timeout_count, count(music_session_id) AS in_session, count(as_musician) AS musicians, count(CASE WHEN udp_reachable THEN 1 ELSE null END) AS udp_reachable_count, count(CASE WHEN is_network_testing THEN 1 ELSE null END) AS is_network_testing_count').first
stats['count'] = result['total'].to_i
stats['scoring_timeout'] = result['scoring_timeout_count'].to_i

View File

@ -193,5 +193,20 @@ describe JamRuby::Connection do
stats['udp_reachable'].should eq(0)
stats['networking_testing'].should eq(0)
end
it "1 connection" do
conn.touch
stats = Connection.stats
stats[Connection::TYPE_CLIENT].should eq(1)
stats[Connection::TYPE_BROWSER].should eq(0)
stats[Connection::TYPE_LATENCY_TESTER].should eq(0)
stats['count'].should eq(1)
stats['scoring_timeout'].should eq(0)
stats['in_session'].should eq(1)
stats['musicians'].should eq(1)
stats['udp_reachable'].should eq(1)
stats['networking_testing'].should eq(0)
end
end
end