VRFS-3391 fixing glitches from mobile tests
This commit is contained in:
parent
5c0178df8f
commit
c1b8bf9ff7
|
|
@ -2,7 +2,7 @@ module JamRuby
|
||||||
class GenreJamTrack < ActiveRecord::Base
|
class GenreJamTrack < ActiveRecord::Base
|
||||||
|
|
||||||
self.table_name = 'genres_jam_tracks'
|
self.table_name = 'genres_jam_tracks'
|
||||||
belongs_to :jam_track, class_name: 'JamRuby::JamTrack'
|
belongs_to :jam_track, class_name: 'JamRuby::JamTrack', inverse_of: :genres_jam_tracks
|
||||||
belongs_to :genre, class_name: 'JamRuby::Genre'
|
belongs_to :genre, class_name: 'JamRuby::Genre', inverse_of: :genres_jam_tracks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
module JamRuby
|
module JamRuby
|
||||||
class JamTrack < ActiveRecord::Base
|
class JamTrack < ActiveRecord::Base
|
||||||
include JamRuby::S3ManagerMixin
|
include JamRuby::S3ManagerMixin
|
||||||
|
|
@ -52,7 +53,7 @@ module JamRuby
|
||||||
|
|
||||||
belongs_to :licensor , class_name: 'JamRuby::JamTrackLicensor', foreign_key: 'licensor_id', :inverse_of => :jam_tracks
|
belongs_to :licensor , class_name: 'JamRuby::JamTrackLicensor', foreign_key: 'licensor_id', :inverse_of => :jam_tracks
|
||||||
|
|
||||||
has_many :genres_jam_tracks, :class_name => "JamRuby::GenreJamTrack", :foreign_key => "jam_track_id"
|
has_many :genres_jam_tracks, :class_name => "JamRuby::GenreJamTrack", :foreign_key => "jam_track_id", inverse_of: :jam_track
|
||||||
has_many :genres, :through => :genres_jam_tracks, :class_name => "JamRuby::Genre", :source => :genre
|
has_many :genres, :through => :genres_jam_tracks, :class_name => "JamRuby::Genre", :source => :genre
|
||||||
|
|
||||||
has_many :jam_track_tracks, :class_name => "JamRuby::JamTrackTrack", order: 'track_type ASC, position ASC, part ASC, instrument_id ASC'
|
has_many :jam_track_tracks, :class_name => "JamRuby::JamTrackTrack", order: 'track_type ASC, position ASC, part ASC, instrument_id ASC'
|
||||||
|
|
@ -255,12 +256,12 @@ module JamRuby
|
||||||
limit = options[:limit]
|
limit = options[:limit]
|
||||||
limit ||= 20
|
limit ||= 20
|
||||||
limit = limit.to_i
|
limit = limit.to_i
|
||||||
|
per_page = limit
|
||||||
else
|
else
|
||||||
limit = per_page
|
limit = per_page
|
||||||
end
|
end
|
||||||
|
|
||||||
start = (page -1 )* per_page
|
start = (page -1 )* per_page
|
||||||
limit = per_page
|
|
||||||
else
|
else
|
||||||
limit = options[:limit]
|
limit = options[:limit]
|
||||||
limit ||= 20
|
limit ||= 20
|
||||||
|
|
@ -340,14 +341,25 @@ module JamRuby
|
||||||
query = query.where("jam_track_tracks.instrument_id = '#{options[:instrument]}' and jam_track_tracks.track_type != 'Master'") unless options[:instrument].blank?
|
query = query.where("jam_track_tracks.instrument_id = '#{options[:instrument]}' and jam_track_tracks.track_type != 'Master'") unless options[:instrument].blank?
|
||||||
query = query.where("jam_tracks.sales_region = '#{options[:availability]}'") unless options[:availability].blank?
|
query = query.where("jam_tracks.sales_region = '#{options[:availability]}'") unless options[:availability].blank?
|
||||||
|
|
||||||
|
# FIXME: n+1 queries for rights and genres
|
||||||
|
# query = query.includes([{ jam_track_tracks: :instrument },
|
||||||
|
# :jam_track_tap_ins,
|
||||||
|
# :jam_track_rights,
|
||||||
|
# :genres])
|
||||||
|
# { genres_jam_tracks: :genre },
|
||||||
|
query = query.includes([{ jam_track_tracks: :instrument },
|
||||||
|
{ genres_jam_tracks: :genre },
|
||||||
|
:jam_track_tap_ins])
|
||||||
|
|
||||||
|
objs = query.all
|
||||||
count = query.total_entries
|
count = query.total_entries
|
||||||
|
|
||||||
if count == 0
|
if count == 0
|
||||||
[query, nil, count]
|
[objs, nil, count]
|
||||||
elsif query.length < limit
|
elsif objs.length < limit
|
||||||
[query, nil, count]
|
[objs, nil, count]
|
||||||
else
|
else
|
||||||
[query, start + limit, count]
|
[objs, start + limit, count]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue