Skip to content

Commit

Permalink
minor fixes (includes to joins)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramensoup committed Aug 28, 2015
1 parent ac7438d commit 5a6e641
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/concerns/tt_query_concern.rb
Expand Up @@ -6,7 +6,7 @@ module TtQueryConcern
scope :visible, lambda { |*args|
user = args.shift || User.current
base = Project.allowed_to_condition(user, @visibile_permission, *args)
scope = includes(:project).where("#{table_name}.project_id IS NULL OR (#{base})")
scope = joins(:project).where("#{table_name}.project_id IS NULL OR (#{base})")

if user.admin?
scope.where("#{table_name}.visibility <> ? OR #{table_name}.user_id = ?", Query::VISIBILITY_PRIVATE, user.id)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tt_overview_controller.rb
Expand Up @@ -68,4 +68,4 @@ def index
def check_settings_for_ajax
flash[:error] = l(:force_auth_requires_rest_api) if Setting.login_required? && !Setting.rest_api_enabled?
end
end
end
4 changes: 2 additions & 2 deletions app/models/report_query.rb
Expand Up @@ -37,7 +37,7 @@ def auth_values
versions = project.shared_versions.all
else
# TODO: find a way to get shared_versions without killing the db
versions = Project.visible.includes(:versions).all.flat_map { |project| project.shared_versions.all }
versions = Project.visible.joins(:versions).all.flat_map { |project| project.shared_versions.all }
versions.uniq!
end

Expand Down Expand Up @@ -95,7 +95,7 @@ def bookings(options={})
order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)

scope = TimeBooking.visible.
includes([:project, {:time_entry => [{:issue => :fixed_version}, :activity]}, {:time_log => :user}]).
joins([:project, {:time_entry => [{:issue => :fixed_version}, :activity]}, {:time_log => :user}]).
where(statement).
where(options[:conditions]).
order(order_option).
Expand Down
4 changes: 2 additions & 2 deletions app/models/time_booking_query.rb
Expand Up @@ -37,7 +37,7 @@ def auth_values
versions = project.shared_versions.all
else
# TODO: find a way to get shared_versions without killing the db
versions = Project.visible.includes(:versions).all.flat_map { |project| project.shared_versions.all }
versions = Project.visible.joins(:versions).all.flat_map { |project| project.shared_versions.all }
versions.uniq!
end

Expand Down Expand Up @@ -95,7 +95,7 @@ def bookings(options={})
order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)

scope = TimeBooking.visible.
includes([:project, {:time_entry => [{:issue => :fixed_version}, :activity]}, {:time_log => :user}]).
joins([:project, {:time_entry => [{:issue => :fixed_version}, :activity]}, {:time_log => :user}]).
where(statement).
where(options[:conditions]).
order(order_option).
Expand Down
6 changes: 3 additions & 3 deletions app/models/time_log_query.rb
Expand Up @@ -26,7 +26,7 @@ def default_columns_names
# Returns the logs count
def log_count
TimeLog.visible.
includes(:user).
joins(:user).
where(statement).
count(:id)
rescue ::ActiveRecord::StatementInvalid => e
Expand All @@ -40,7 +40,7 @@ def log_count_by_group
begin
gbs = group_by_statement
r = TimeLog.visible.
includes(:user).
joins(:user).
group(gbs).
where(statement).
count(:id)
Expand All @@ -62,7 +62,7 @@ def logs(options={})
order_option = nil if order_option.blank?

TimeLog.visible.
includes(:user, :time_bookings).
joins(:user, :time_bookings).
where(statement).
order(order_option).
limit(options[:limit]).
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -21,7 +21,7 @@

match '/tt_overview', :to => 'tt_overview#index', :via => [:get, :post]

match '/time_trackers/stop', :to => 'time_trackers#stop', :via => [:get, :put, :post]
match '/time_trackers/stop', :to => 'time_trackers#stop', :via => [:get, :put, :post, :patch]
match '/time_trackers/start', :to => 'time_trackers#start', :via => [:post, :get]
match '/time_trackers/update', :to => 'time_trackers#update', :via => [:get, :put]
match '/time_trackers/delete', :to => 'time_trackers#delete', :via => [:get, :post]
Expand Down

0 comments on commit 5a6e641

Please sign in to comment.