diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-06-19 20:24:14 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-06-28 19:51:05 +0300 |
commit | 1fbb7f977777de7c8808429693359c7a98ffdfcc (patch) | |
tree | bb872e346a9fb3b6c6d9001196ee931dba632387 /app | |
parent | 34f57b462bc14ad194cf890a4585d403bdbde55c (diff) |
Removes redundant pending delete checks
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/todos_finder.rb | 3 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 4 | ||||
-rw-r--r-- | app/models/namespace.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/services/ci/register_job_service.rb | 6 |
5 files changed, 10 insertions, 10 deletions
diff --git a/app/finders/todos_finder.rb b/app/finders/todos_finder.rb index 5a4c5767be5..3fe37c75381 100644 --- a/app/finders/todos_finder.rb +++ b/app/finders/todos_finder.rb @@ -78,7 +78,6 @@ class TodosFinder end def project - return nil if @project&.pending_delete? return @project if defined?(@project) if project? @@ -98,7 +97,7 @@ class TodosFinder def projects(items) item_project_ids = items.reorder(nil).select(:project_id) - ProjectsFinder.new(current_user: current_user, project_ids_relation: item_project_ids).execute.without_deleted + ProjectsFinder.new(current_user: current_user, project_ids_relation: item_project_ids).execute end def type? diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 9c46035057f..8f15904f068 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -97,8 +97,8 @@ module SearchHelper # Autocomplete results for the current user's projects def projects_autocomplete(term, limit = 5) - current_user.authorized_projects.search_by_title(term). - sorted_by_stars.non_archived.limit(limit).map do |p| + current_user.authorized_projects.search_by_title(term) + .sorted_by_stars.non_archived.limit(limit).map do |p| { category: "Projects", id: p.id, diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 583d4fb5244..efbed5a2ef5 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -47,6 +47,8 @@ class Namespace < ActiveRecord::Base before_destroy(prepend: true) { prepare_for_destroy } after_destroy :rm_dir + default_scope { with_deleted } + scope :for_user, -> { where('type IS NULL') } scope :with_statistics, -> do diff --git a/app/models/project.rb b/app/models/project.rb index 40a8e7f07c6..65f81727071 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -222,7 +222,7 @@ class Project < ActiveRecord::Base has_many :uploads, as: :model, dependent: :destroy # Scopes - scope :with_deleted, -> { where(pending_delete: true) } + scope :pending_delete, -> { where(pending_delete: true) } scope :without_deleted, -> { where(pending_delete: false) } scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } @@ -376,7 +376,6 @@ class Project < ActiveRecord::Base .or(ptable[:description].matches(pattern)) ) - namespaces = unscoped.select(:id) .joins(:namespace) .where(ntable[:name].matches(pattern)) @@ -1456,7 +1455,7 @@ class Project < ActiveRecord::Base def pending_delete_twin return false unless path - Project.with_deleted.find_by_full_path(path_with_namespace) + Project.pending_delete.find_by_full_path(path_with_namespace) end ## diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb index 27bdb6b9a2f..b951e8d0c9f 100644 --- a/app/services/ci/register_job_service.rb +++ b/app/services/ci/register_job_service.rb @@ -54,9 +54,9 @@ module Ci def builds_for_shared_runner new_builds. # don't run projects which have not enabled shared runners and builds - joins(:project).where(projects: { shared_runners_enabled: true, pending_delete: false }). - joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id'). - where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0'). + joins(:project).where(projects: { shared_runners_enabled: true, pending_delete: false }) + .joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id') + .where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0'). # Implement fair scheduling # this returns builds that are ordered by number of running builds |