Skip to content

Commit

Permalink
Merge pull request #16110 from hennevogel/refactoring/user-requests-q…
Browse files Browse the repository at this point in the history
…ueries

Speed up query
  • Loading branch information
saraycp committed May 10, 2024
2 parents f60852d + 319fed1 commit d5573df
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ def destroy_home_projects(reason:)
end

def involved_projects
Project.for_user(id).or(Project.for_group(group_ids))
Project.unscoped.for_user(id).or(Project.unscoped.for_group(group_ids))
end

# lists packages maintained by this user and are not in maintained projects
def involved_packages
Package.for_user(id).or(Package.for_group(group_ids)).where.not(project: involved_projects)
Package.unscoped.for_user(id).or(Package.unscoped.for_group(group_ids)).where.not(project: involved_projects)
end

# lists reviews involving this user
Expand All @@ -710,8 +710,8 @@ def declined_requests(search = nil)

# list incoming requests involving this user
def incoming_requests(search = nil, states: [:new])
result = BsRequest.where(id: BsRequestAction.bs_request_ids_of_involved_projects(involved_projects)).or(
BsRequest.where(id: BsRequestAction.bs_request_ids_of_involved_packages(involved_packages))
result = BsRequest.where(state: states).where(id: BsRequestAction.bs_request_ids_of_involved_projects(involved_projects.pluck(:id))).or(
BsRequest.where(id: BsRequestAction.bs_request_ids_of_involved_packages(involved_packages.pluck(:id)))
).with_actions.where(state: states)

search.present? ? result.do_search(search) : result
Expand All @@ -725,8 +725,8 @@ def outgoing_requests(search = nil, states: %i[new review])

# list of all requests
def requests(search = nil)
project_ids = involved_projects
package_ids = involved_packages
project_ids = involved_projects.pluck(:id)
package_ids = involved_packages.pluck(:id)

actions = BsRequestAction.bs_request_ids_of_involved_projects(project_ids).or(
BsRequestAction.bs_request_ids_of_involved_packages(package_ids)
Expand Down

0 comments on commit d5573df

Please sign in to comment.