Compare commits

...

1 Commits

Author SHA1 Message Date
ulferts ab614278e9
improve visiblity scope performance by EXIST 2 years ago
  1. 8
      app/models/notifications/scopes/visible.rb
  2. 7
      app/models/work_package.rb

@ -36,9 +36,15 @@ module Notifications::Scopes
# * the user has the permission to see the associated resource
#
# As currently only notifications for work packages exist, the implementation is work package specific.
# Using EXISTS as this performs better.
def visible(user)
recipient(user)
.where(resource_type: 'WorkPackage', resource_id: WorkPackage.visible(user).select(:id))
.where(resource_type: 'WorkPackage')
.where(WorkPackage
.visible(user)
.where("#{Notification.table_name}.resource_id = #{WorkPackage.table_name}.id")
.arel
.exists)
end
end
end

@ -72,7 +72,12 @@ class WorkPackage < ApplicationRecord
}
scope :visible, ->(*args) {
where(project_id: Project.allowed_to(args.first || User.current, :view_work_packages))
# Using EXISTS as this performs better.
where(Project
.allowed_to(args.first || User.current, :view_work_packages)
.where("#{WorkPackage.table_name}.project_id = #{Project.table_name}.id")
.arel
.exists)
}
scope :in_status, ->(*args) do

Loading…
Cancel
Save