* resolving VRFS-2624 - if nil recording_ids, just exit early

This commit is contained in:
Seth Call 2015-01-08 10:25:54 -06:00
parent 3fb5ab89d9
commit e28db48e94
3 changed files with 190 additions and 118 deletions

View File

@ -57,22 +57,26 @@ module JamRuby
limit = 1000 limit = 1000
recording_ids = recording_ids.uniq if recording_ids.nil?
return []
else
recording_ids = recording_ids.uniq
raise "too many recording_ids" if recording_ids.length > limit raise "too many recording_ids" if recording_ids.length > limit
found_recording_ids = found_recording_ids =
UserSync UserSync
.select('user_syncs.recording_id') .select('user_syncs.recording_id')
.joins("LEFT OUTER JOIN claimed_recordings ON claimed_recordings.user_id = user_syncs.user_id") .joins("LEFT OUTER JOIN claimed_recordings ON claimed_recordings.user_id = user_syncs.user_id")
.where(%Q{ .where(%Q{
((claimed_recordings IS NULL OR claimed_recordings.discarded = TRUE) AND fully_uploaded = FALSE) OR (claimed_recordings IS NOT NULL AND claimed_recordings.discarded = FALSE) ((claimed_recordings IS NULL OR claimed_recordings.discarded = TRUE) AND fully_uploaded = FALSE) OR (claimed_recordings IS NOT NULL AND claimed_recordings.discarded = FALSE)
}) })
.where(user_id: user_id) .where(user_id: user_id)
.paginate(:page => 1, :per_page => limit) .paginate(:page => 1, :per_page => limit)
.group('user_syncs.recording_id').map(&:recording_id) .group('user_syncs.recording_id').map(&:recording_id)
recording_ids - found_recording_ids recording_ids - found_recording_ids
end
end end
end end
end end

View File

@ -352,6 +352,12 @@ describe UserSync do
result.should eq(['1']) result.should eq(['1'])
end end
it "null recording_ids allowed" do
# observed that the client can send null for recording_ids
result = UserSync.deletables(user_id: mix.recording.recorded_tracks[0].user.id, recording_ids: nil)
result.should eq([])
end
end end
describe "two recordings" do describe "two recordings" do

View File

@ -1,32 +1,34 @@
require 'factory_girl' require 'factory_girl'
require 'open-uri'
namespace :db do namespace :db do
desc "Add a simple one track recording to the database" desc "Add a simple one track recording to the database"
task single_recording: :environment do task single_recording: :environment do
User.where(:musician => true).order('RANDOM()').limit(10).each do |uu| User.where(:musician => true).order('RANDOM()').limit(10).each do |uu|
@user = uu @user = uu
next if @user.connections.present? next if @user.connections.present?
@connection = FactoryGirl.create(:connection, :user => @user) @connection = FactoryGirl.create(:connection, :user => @user)
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => Instrument.find('violin'), :client_track_id => "t1") @track = FactoryGirl.create(:track, :connection => @connection, :instrument => Instrument.find('violin'), :client_track_id => "t1")
@music_session = FactoryGirl.create(:active_music_session, :creator => @user, :musician_access => true) @music_session = FactoryGirl.create(:active_music_session, :creator => @user, :musician_access => true)
@music_session.connections << @connection @music_session.connections << @connection
@music_session.save @music_session.save
@recording = FactoryGirl.create(:recording, :music_session => @music_session, :owner => @user, :id=>"R#{rand(10000)}") @recording = FactoryGirl.create(:recording, :music_session => @music_session, :owner => @user, :id => "R#{rand(10000)}")
@recorded_track = RecordedTrack.create_from_track(@track, @recording) @recorded_track = RecordedTrack.create_from_track(@track, @recording)
@recorded_track.save @recorded_track.save
#@recording = Recording.start(@music_session, @user) #@recording = Recording.start(@music_session, @user)
@recording.stop @recording.stop
@recording.reload @recording.reload
@genre = Genre.find('ambient') @genre = Genre.find('ambient')
@recording.claim(@user, "name", "description", @genre, true) @recording.claim(@user, "name", "description", @genre, true)
@recording.reload @recording.reload
@claimed_recording = @recording.claimed_recordings.first @claimed_recording = @recording.claimed_recordings.first
end end
end end
task clean: :environment do task clean: :environment do
DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres users] } DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres users]}
DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres users] }) DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres users]})
DatabaseCleaner.start DatabaseCleaner.start
DatabaseCleaner.clean DatabaseCleaner.clean
end end
@ -86,36 +88,36 @@ namespace :db do
end end
def make_music_sessions_history def make_music_sessions_history
users = User.all.map(&:id) users = User.all.map(&:id)
bands = Band.all.map(&:id) bands = Band.all.map(&:id)
genres = Genre.all.map(&:description) genres = Genre.all.map(&:description)
50.times do |nn| 50.times do |nn|
obj = MusicSession.new obj = MusicSession.new
obj.music_session_id = rand(100000000).to_s obj.music_session_id = rand(100000000).to_s
obj.description = Faker::Lorem.paragraph obj.description = Faker::Lorem.paragraph
obj.user_id = users[rand(users.count)] obj.user_id = users[rand(users.count)]
obj.band_id = bands[rand(bands.count)] obj.band_id = bands[rand(bands.count)]
obj.created_at = Time.now - rand(1.month.seconds) obj.created_at = Time.now - rand(1.month.seconds)
obj.session_removed_at = obj.created_at + (rand(3)+1).hour obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.genres = genres.shuffle[0..rand(4)].join(' | ') obj.genres = genres.shuffle[0..rand(4)].join(' | ')
obj.save! obj.save!
end end
end end
def make_music_sessions_user_history def make_music_sessions_user_history
users = User.all.map(&:id) users = User.all.map(&:id)
hists = MusicSession.all hists = MusicSession.all
hists.each do |msh| hists.each do |msh|
(rand(9)+1).times do |nn| (rand(9)+1).times do |nn|
obj = MusicSessionUserHistory.new obj = MusicSessionUserHistory.new
obj.music_session_id = msh.music_session_id obj.music_session_id = msh.music_session_id
obj.user_id = users[rand(users.count)] obj.user_id = users[rand(users.count)]
obj.created_at = msh.created_at obj.created_at = msh.created_at
obj.session_removed_at = obj.created_at + (rand(3)+1).hour obj.session_removed_at = obj.created_at + (rand(3)+1).hour
obj.client_id = rand(100000000).to_s obj.client_id = rand(100000000).to_s
obj.save! obj.save!
end
end end
end
end end
def make_band_members def make_band_members
@ -136,51 +138,51 @@ def make_band_genres
end end
def make_bands def make_bands
10.times do |nn| 10.times do |nn|
name = Faker::Name.name name = Faker::Name.name
website = Faker::Internet.url website = Faker::Internet.url
biography = Faker::Lorem.sentence biography = Faker::Lorem.sentence
city = 'Austin' # Faker::Address.city city = 'Austin' # Faker::Address.city
state = 'TX' # Faker::Address.state_abbr state = 'TX' # Faker::Address.state_abbr
country = 'US' country = 'US'
bb = Band.new( bb = Band.new(
name: name, name: name,
website: website, website: website,
biography: biography, biography: biography,
city: city, city: city,
state: state, state: state,
country: country, country: country,
) )
Genre.order('RANDOM()').limit(rand(3)+1).each do |gg| Genre.order('RANDOM()').limit(rand(3)+1).each do |gg|
bb.genres << gg bb.genres << gg
end end
begin begin
bb.save! bb.save!
rescue rescue
puts $!.to_s + ' ' + bb.errors.inspect puts $!.to_s + ' ' + bb.errors.inspect
end end
end end
end end
def make_users(num=99) def make_users(num=99)
admin = User.create!( first_name: Faker::Name.name, admin = User.create!(first_name: Faker::Name.name,
last_name: Faker::Name.name, last_name: Faker::Name.name,
email: "example@railstutorial.org", email: "example@railstutorial.org",
password: "foobar", password: "foobar",
password_confirmation: "foobar", password_confirmation: "foobar",
terms_of_service: true) terms_of_service: true)
admin.toggle!(:admin) admin.toggle!(:admin)
num.times do |n| num.times do |n|
email = "example-#{n+1}@railstutorial.org" email = "example-#{n+1}@railstutorial.org"
password = "password" password = "password"
User.create!(first_name: Faker::Name.name, User.create!(first_name: Faker::Name.name,
last_name: Faker::Name.name, last_name: Faker::Name.name,
terms_of_service: true, terms_of_service: true,
email: email, email: email,
password: password, password: password,
password_confirmation: password) password_confirmation: password)
end end
@ -196,11 +198,11 @@ end
def make_relationships def make_relationships
users = User.all users = User.all
user = users.first user = users.first
followed_users = users[2..50] followed_users = users[2..50]
followers = users[3..40] followers = users[3..40]
followed_users.each { |followed| user.followings << followed } followed_users.each { |followed| user.followings << followed }
followers.each { |follower| follower.follow!(user) } followers.each { |follower| follower.follow!(user) }
end end
def make_followings def make_followings
@ -210,7 +212,7 @@ def make_followings
uuu.followings << uu unless 0 < Follow.where(:followable_id => uu.id, :user_id => uuu.id).count uuu.followings << uu unless 0 < Follow.where(:followable_id => uu.id, :user_id => uuu.id).count
uu.followings << uuu unless 0 < Follow.where(:followable_id => uuu.id, :user_id => uu.id).count if rand(3)==0 uu.followings << uuu unless 0 < Follow.where(:followable_id => uuu.id, :user_id => uu.id).count if rand(3)==0
end end
end end
end end
def make_friends def make_friends
@ -219,7 +221,7 @@ def make_friends
users[0..5].shuffle.each do |uuu| users[0..5].shuffle.each do |uuu|
Friendship.save(uu.id, uuu.id) Friendship.save(uu.id, uuu.id)
end end
end end
end end
def make_recorded_track(recording, user, instrument, md5, length, filename) def make_recorded_track(recording, user, instrument, md5, length, filename)
@ -249,11 +251,10 @@ def make_claimed_recording(recording, user, name, description)
end end
def make_recording def make_recording
# need 4 users. # need 4 users.
users = User.where(musician: true).limit(4) users = User.where(musician: true).limit(4)
raise "need at least 4 musicians in the database to create a recording" if users.length < 4 raise "need at least 4 musicians in the database to create a recording" if users.length < 4
user1 = users[0] user1 = users[0]
user2 = users[1] user2 = users[1]
@ -264,13 +265,13 @@ def make_recording
recording.name = 'sample data' recording.name = 'sample data'
recording.owner = user1 recording.owner = user1
make_recorded_track(recording, user1, 'bass guitar', 'f86949abc213a3ccdc9d266a2ee56453', 2579467, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-bass.ogg') make_recorded_track(recording, user1, 'bass guitar', 'f86949abc213a3ccdc9d266a2ee56453', 2579467, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-bass.ogg')
make_recorded_track(recording, user1, 'voice', '264cf4e0bf14d44109322a504d2e6d18', 2373055, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg') make_recorded_track(recording, user1, 'voice', '264cf4e0bf14d44109322a504d2e6d18', 2373055, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg')
make_recorded_track(recording, user2, 'electric guitar', '9f322e1991b8c04b00dc9055d6be933c', 2297867, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-guitar.ogg') make_recorded_track(recording, user2, 'electric guitar', '9f322e1991b8c04b00dc9055d6be933c', 2297867, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-guitar.ogg')
make_recorded_track(recording, user2, 'voice', '3c7dcb7c4c35c0bb313fc15ee3e6bfd5', 2244968, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-vox.ogg') make_recorded_track(recording, user2, 'voice', '3c7dcb7c4c35c0bb313fc15ee3e6bfd5', 2244968, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-chris-vox.ogg')
make_recorded_track(recording, user3, 'voice', '10ca4c6ef5b98b3489ae8da1c7fa9cfb', 2254275, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-matt-lead-vox.ogg') make_recorded_track(recording, user3, 'voice', '10ca4c6ef5b98b3489ae8da1c7fa9cfb', 2254275, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-matt-lead-vox.ogg')
make_recorded_track(recording, user4, 'drums', 'ea366f482fa969e1fd8530c13cb75716', 2386250, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum1.ogg') make_recorded_track(recording, user4, 'drums', 'ea366f482fa969e1fd8530c13cb75716', 2386250, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum1.ogg')
make_recorded_track(recording, user4, 'drums', '4c693c6e99117719c6340eb68b0fe574', 2566463, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum2.ogg') make_recorded_track(recording, user4, 'drums', '4c693c6e99117719c6340eb68b0fe574', 2566463, 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/track-randy-drum2.ogg')
make_claimed_recording(recording, user1, 'Poison', 'Classic song that you all know -- user1') make_claimed_recording(recording, user1, 'Poison', 'Classic song that you all know -- user1')
make_claimed_recording(recording, user2, 'Poison', 'Classic song that you all know -- user2') make_claimed_recording(recording, user2, 'Poison', 'Classic song that you all know -- user2')
@ -278,7 +279,7 @@ def make_recording
make_claimed_recording(recording, user4, 'Poison', 'Classic song that you all know -- user4') make_claimed_recording(recording, user4, 'Poison', 'Classic song that you all know -- user4')
mix = Mix.new mix = Mix.new
mix.started_at = Time.now mix.started_at = Time.now
mix.completed_at = Time.now mix.completed_at = Time.now
mix[:ogg_url] = 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/master-out.ogg' mix[:ogg_url] = 'https://jamjam:blueberryjam@int.jamkazam.com/stuff/lc_rocks_poison/master-out.ogg'
mix.ogg_md5 = 'f1fee708264602e1705638e53f0ea667' mix.ogg_md5 = 'f1fee708264602e1705638e53f0ea667'
@ -288,26 +289,87 @@ def make_recording
mix.mp3_length = 3666137 mix.mp3_length = 3666137
mix.completed = true mix.completed = true
recording.mixes << mix recording.mixes << mix
recording.save!(validate:false) recording.save!(validate: false)
end end
def make_jam_track(user) def make_jam_track(user)
number = 0 number = 0
track = JamTrack.where('name like ?', 'boostrapped-%').order('name DESC').first JamTrack.transaction do
if track
index = track.name.index('-') track = JamTrack.where('name like ?', 'bootstrapped-%').order('name DESC').first
number = track.name[index+1..-1].to_i + 1 # increment most recent bootstrapped by 1 if track
puts "found existing JamTrack with name #{track.name}"
index = track.name.index('-')
number = track.name[index+1..-1].to_i + 1 # increment most recent bootstrapped by 1
end
suffix = number.to_s.rjust(3, '0') # 0 pad a bit
new_name ='bootstrapped-' + suffix
puts "creating jam_track with name #{new_name}"
licensor = JamTrackLicensor.first
if licensor
jam_track = FactoryGirl.create(:jam_track, name: new_name, licensor: licensor)
else
jam_track = FactoryGirl.create(:jam_track, name: new_name)
end
jam_track_track = jam_track.jam_track_tracks[0]
download_filename = Dir::Tmpname.make_tmpname(["#{Dir.tmpdir}/bootstrapped-" + suffix, '.ogg'], nil)
puts "downloading ogg file from int.jamkazam.com"
File.open(download_filename, "wb") do |saved_file|
open("https://int.jamkazam.com/stuff/lc_rocks_poison/track-adrian-vox.ogg", "rb", {http_basic_authentication: ["jamjam", "blueberryjam"]}) do |read_file|
saved_file.write(read_file.read)
end
end
puts "uploading ogg file to s3"
# let's put in a real ogg file into S3, so that the JamTracksBuilder job can succeed
s3_manager = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
url = jam_track_track.store_dir + "/" + jam_track_track.filename
s3_manager.upload(url, download_filename)
jam_track_track[:url] = url
jam_track_track.length = File.size(download_filename)
jam_track_track.md5 = '264cf4e0bf14d44109322a504d2e6d18'
jam_track_track.save!
puts "'purchasing' jamtrack for user #{user.email}"
right = FactoryGirl.create(:jam_track_right, user: user, jam_track: jam_track)
puts "creating .jkz file"
JamTracksBuilder.perform(right.id)
puts "------------------------------------"
puts "------------------------------------"
puts "---- SAVING JKZ AND PEM TO DISK ----"
puts "------------------------------------"
puts "------------------------------------"
right.reload
jkz_outfile = "tmp/#{jam_track.id}.jkz"
jkz_private_key = "tmp/#{jam_track.id}.pem"
File.open(jkz_private_key, 'w') {|f| f.write(right.private_key) }
s3_manager.download(right[:url], jkz_outfile)
puts "------------------------------------"
puts "------------------------------------"
puts "JKZ PACKAGE: #{jkz_outfile}"
puts "JKZ PRIVATE KEY: #{jkz_private_key}"
puts "------------------------------------"
puts "------------------------------------"
end end
suffix = number.to_s.rjust(3, '0') # 0 pad a bit
jam_track = FactoryGirl.create(:jam_track, name: 'bootstrapped-' + suffix)
right = FactoryGirl.create(:jam_track_right, user: user, jam_track: jam_track)
JamTracksBuilder.perform(right.id)
end end
def populate_conversation(target_email) def populate_conversation(target_email)