Commit 4a915c73 authored by Yorick Peterse's avatar Yorick Peterse

Remove redundant query from User#recent_push

The "events" table has a foreign key on "events.project_id" with a
cascading delete. As such it's impossible for an event to have a
non-existing project ID.
parent f77fda64
...@@ -646,18 +646,16 @@ class User < ActiveRecord::Base ...@@ -646,18 +646,16 @@ class User < ActiveRecord::Base
events = events.where(project_id: project_ids) if project_ids events = events.where(project_id: project_ids) if project_ids
# Use the latest event that has not been pushed or merged recently # Use the latest event that has not been pushed or merged recently
events.recent.find do |event| events.includes(:project).recent.find do |event|
project = Project.find_by_id(event.project_id) next unless event.project.repository.branch_exists?(event.branch_name)
next unless project
if project.repository.branch_exists?(event.branch_name)
merge_requests = MergeRequest.where("created_at >= ?", event.created_at) merge_requests = MergeRequest.where("created_at >= ?", event.created_at)
.where(source_project_id: project.id, .where(source_project_id: event.project.id,
source_branch: event.branch_name) source_branch: event.branch_name)
merge_requests.empty? merge_requests.empty?
end end
end end
end
def projects_sorted_by_activity def projects_sorted_by_activity
authorized_projects.sorted_by_activity authorized_projects.sorted_by_activity
......
---
title: Remove redundant query when retrieving the most recent push of a user
merge_request:
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment