wire up live latency and tag; accessors for tag and latency; fix borked function def; ams_init function; ams transaction
This commit is contained in:
parent
2799a6443e
commit
3c3565893d
|
|
@ -172,3 +172,4 @@ latency_tester.sql
|
|||
scheduled_sessions_next_session_scheduled.sql
|
||||
fix_users_location_fields.sql
|
||||
audio_latency.sql
|
||||
ams_index.sql
|
||||
|
|
|
|||
|
|
@ -1,10 +1,4 @@
|
|||
-- DROP FUNCTION IF EXISTS ams_index (my_user_id VARCHAR, my_locidispid BIGINT, my_audio_latency INTEGER, poff INTEGER, plim INTEGER);
|
||||
CREATE OR REPLACE FUNCTION ams_index (my_user_id VARCHAR, my_locidispid BIGINT, my_audio_latency INTEGER)
|
||||
RETURNS VOID
|
||||
LANGUAGE plpgsql
|
||||
STRICT
|
||||
VOLATILE
|
||||
AS $$
|
||||
CREATE OR REPLACE FUNCTION ams_index (my_user_id VARCHAR, my_locidispid BIGINT, my_audio_latency INTEGER) RETURNS VOID STRICT VOLATILE AS $$
|
||||
BEGIN
|
||||
-- output table to hold tagged music sessions with latency
|
||||
CREATE TEMPORARY TABLE ams_music_session_tmp (music_session_id VARCHAR(64) NOT NULL, tag INTEGER, latency INTEGER) ON COMMIT DROP;
|
||||
|
|
@ -59,4 +53,4 @@ AS $$
|
|||
|
||||
RETURN;
|
||||
END;
|
||||
$$;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
|
|
|||
|
|
@ -314,6 +314,17 @@ module JamRuby
|
|||
return query
|
||||
end
|
||||
|
||||
# initialize the two temporary tables we use to drive ams_index
|
||||
def self.ams_init(current_user, options = {})
|
||||
client_id = options[:client_id]
|
||||
|
||||
connection = Connection.where(user_id: current_user.id, client_id: client_id).first!
|
||||
my_locidispid = connection.locidispid
|
||||
my_audio_latency = connection.last_jam_audio_latency
|
||||
|
||||
self.connection.execute("select ams_index('#{current_user.id}'::varchar, #{my_locidispid}::bigint, #{my_audio_latency}::integer)");
|
||||
end
|
||||
|
||||
# Generate a list of music sessions (that are active) filtered by genre, language, keyword, and sorted
|
||||
# (and tagged) by rsvp'd (1st), invited (2nd), and musician can join (3rd). within a group
|
||||
# tagged the same, sorted by score. date seems irrelevant as these are active sessions.
|
||||
|
|
@ -332,29 +343,29 @@ module JamRuby
|
|||
query = MusicSession
|
||||
.select('music_sessions.*')
|
||||
|
||||
# TODO this is not really needed when ams_music_session_tmp is joined
|
||||
# this is not really needed when ams_music_session_tmp is joined
|
||||
# unless there is something specific we need out of active_music_sessions
|
||||
query = query.joins(
|
||||
%Q{
|
||||
INNER JOIN
|
||||
active_music_sessions
|
||||
ON
|
||||
active_music_sessions.id = music_sessions.id
|
||||
}
|
||||
)
|
||||
.select('1::integer as tag, 15::integer as latency')
|
||||
|
||||
# TODO integrate ams_music_session_tmp into the processing
|
||||
# then we can join ams_music_session_tmp and not join active_music_sessions
|
||||
# query = query.joins(
|
||||
# %Q{
|
||||
# INNER JOIN
|
||||
# ams_music_session_tmp
|
||||
# active_music_sessions
|
||||
# ON
|
||||
# ams_music_session_tmp.music_session_id = active_music_sessions.id
|
||||
# active_music_sessions.id = music_sessions.id
|
||||
# }
|
||||
# )
|
||||
# .select('ams_music_session_tmp.tag, ams_music_session_tmp.latency')
|
||||
# .select('1::integer as tag, 15::integer as latency')
|
||||
|
||||
# integrate ams_music_session_tmp into the processing
|
||||
# then we can join ams_music_session_tmp and not join active_music_sessions
|
||||
query = query.joins(
|
||||
%Q{
|
||||
INNER JOIN
|
||||
ams_music_session_tmp
|
||||
ON
|
||||
ams_music_session_tmp.music_session_id = music_sessions.id
|
||||
}
|
||||
)
|
||||
.select('ams_music_session_tmp.tag, ams_music_session_tmp.latency')
|
||||
|
||||
query = query.order(
|
||||
%Q{
|
||||
|
|
|
|||
|
|
@ -533,6 +533,18 @@ module JamRuby
|
|||
token.gsub(/[^0-9A-Za-z]/, '')
|
||||
end
|
||||
|
||||
def tag
|
||||
nil unless has_attribute?(:tag)
|
||||
a = read_attribute(:tag)
|
||||
a.nil? ? nil : a.to_i
|
||||
end
|
||||
|
||||
def latency
|
||||
nil unless has_attribute?(:latency)
|
||||
a = read_attribute(:latency)
|
||||
a.nil? ? nil : a.to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_share_token
|
||||
|
|
|
|||
|
|
@ -335,24 +335,36 @@ describe ActiveMusicSession do
|
|||
describe "ams_index" do
|
||||
it "does not crash" do
|
||||
|
||||
creator = FactoryGirl.create(:user)
|
||||
creator2 = FactoryGirl.create(:user)
|
||||
creator = FactoryGirl.create(:user, last_jam_locidispid: 1, last_jam_audio_latency: 5)
|
||||
creator2 = FactoryGirl.create(:user, last_jam_locidispid: 2, last_jam_audio_latency: 10)
|
||||
|
||||
earlier_session = FactoryGirl.create(:active_music_session, :creator => creator, :description => "Earlier Session")
|
||||
c1 = FactoryGirl.create(:connection, user: creator, music_session: earlier_session, addr: 0x01020304, locidispid: 1)
|
||||
c1 = FactoryGirl.create(:connection, user: creator, music_session: earlier_session, locidispid: 1, last_jam_audio_latency: 5)
|
||||
|
||||
later_session = FactoryGirl.create(:active_music_session, :creator => creator2, :description => "Later Session")
|
||||
c2 = FactoryGirl.create(:connection, user: creator2, music_session: later_session, addr: 0x21020304, locidispid: 2)
|
||||
c2 = FactoryGirl.create(:connection, user: creator2, music_session: later_session, locidispid: 2, last_jam_audio_latency: 10)
|
||||
|
||||
user = FactoryGirl.create(:user)
|
||||
c3 = FactoryGirl.create(:connection, user: user, locidispid: 3)
|
||||
user = FactoryGirl.create(:user, last_jam_locidispid: 1, last_jam_audio_latency: 5)
|
||||
c3 = FactoryGirl.create(:connection, user: user, locidispid: 1, last_jam_audio_latency: 5)
|
||||
|
||||
Score.createx(c1.locidispid, c1.client_id, c1.addr, c3.locidispid, c3.client_id, c3.addr, 20, nil);
|
||||
Score.createx(c2.locidispid, c2.client_id, c2.addr, c3.locidispid, c3.client_id, c3.addr, 30, nil);
|
||||
|
||||
music_sessions = ActiveMusicSession.ams_index(user, client_id: c3.client_id).take(100)
|
||||
music_sessions.should_not be_nil
|
||||
music_sessions.length.should == 2
|
||||
# make a transaction
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
|
||||
ActiveMusicSession.ams_init(user, client_id: c3.client_id)
|
||||
|
||||
music_sessions = ActiveMusicSession.ams_index(user, client_id: c3.client_id).take(100)
|
||||
music_sessions.should_not be_nil
|
||||
music_sessions.length.should == 2
|
||||
music_sessions[0].tag.should_not be_nil
|
||||
music_sessions[0].latency.should_not be_nil
|
||||
music_sessions[1].tag.should_not be_nil
|
||||
music_sessions[1].latency.should_not be_nil
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# todo we need more tests:
|
||||
|
|
|
|||
|
|
@ -66,13 +66,20 @@ class ApiMusicSessionsController < ApiController
|
|||
# filtered by genre, lang, and keyword, then paged by offset and limit (those are record numbers not page numbers).
|
||||
# tag is 1 for chosen rsvp'd sessions, 2 for invited sessions, 3 for all others (musician_access). if you're the
|
||||
# creator of a session it will be treated the same as if you had rsvp'd and been accepted.
|
||||
@music_sessions = ActiveMusicSession.ams_index(current_user,
|
||||
client_id: params[:client_id],
|
||||
genre: params[:genre],
|
||||
lang: params[:lang],
|
||||
keyword: params[:keyword],
|
||||
offset: params[:offset],
|
||||
limit: params[:limit])
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
ActiveMusicSession.ams_init(current_user, client_id: params[:client_id])
|
||||
|
||||
@music_sessions = ActiveMusicSession.ams_index(current_user,
|
||||
client_id: params[:client_id],
|
||||
genre: params[:genre],
|
||||
lang: params[:lang],
|
||||
keyword: params[:keyword],
|
||||
offset: params[:offset],
|
||||
limit: params[:limit])
|
||||
|
||||
# todo do something with saved music list ams_users_tmp?
|
||||
end
|
||||
end
|
||||
|
||||
def scheduled
|
||||
|
|
|
|||
Loading…
Reference in New Issue