Dramatically improve RfC query
While the code gets more complex, the new query will first filter all relevant RfCs and only use the `with_last_activity` scope for the current page. Using `distinct` in the policy is not required (no duplicated RfCs), but causes issues for the ordering otherwise. Therefore, it is removed. Fixes CODEOCEAN-J2
This commit is contained in:
@ -63,14 +63,14 @@ class RequestForCommentPolicy < ApplicationPolicy
|
||||
when 'all'
|
||||
@scope.all
|
||||
when 'consumer'
|
||||
rfcs_with_users = @scope.distinct
|
||||
rfcs_with_users = @scope
|
||||
.joins('LEFT OUTER JOIN external_users ON request_for_comments.user_type = \'ExternalUser\' AND request_for_comments.user_id = external_users.id')
|
||||
.joins('LEFT OUTER JOIN internal_users ON request_for_comments.user_type = \'InternalUser\' AND request_for_comments.user_id = internal_users.id')
|
||||
|
||||
rfcs_with_users.where(external_users: {consumer_id: @user.consumer.id})
|
||||
.or(rfcs_with_users.where(internal_users: {consumer_id: @user.consumer.id}))
|
||||
when 'study_group'
|
||||
@scope.distinct
|
||||
@scope
|
||||
.joins(:submission)
|
||||
.where(submission: {study_group: @user.current_study_group_id})
|
||||
else
|
||||
|
Reference in New Issue
Block a user