diff options
Diffstat (limited to 'app/models')
41 files changed, 65 insertions, 66 deletions
diff --git a/app/models/blob_viewer/dependency_manager.rb b/app/models/blob_viewer/dependency_manager.rb index a851f22bfcd..a3801025cd7 100644 --- a/app/models/blob_viewer/dependency_manager.rb +++ b/app/models/blob_viewer/dependency_manager.rb @@ -33,7 +33,7 @@ module BlobViewer @json_data ||= begin prepare! Gitlab::Json.parse(blob.data) - rescue + rescue StandardError {} end end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 3d8e9f4c126..bb668fb7cde 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -330,7 +330,7 @@ module Ci begin build.deployment.drop! - rescue => e + rescue StandardError => e Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e, build_id: build.id) end diff --git a/app/models/ci/deleted_object.rb b/app/models/ci/deleted_object.rb index 2942a153e05..b2a949c9bb5 100644 --- a/app/models/ci/deleted_object.rb +++ b/app/models/ci/deleted_object.rb @@ -29,7 +29,7 @@ module Ci def delete_file_from_storage file.remove! true - rescue => exception + rescue StandardError => exception Gitlab::ErrorTracking.track_exception(exception) false end diff --git a/app/models/ci/persistent_ref.rb b/app/models/ci/persistent_ref.rb index 91163c85a9e..57aa1962bd2 100644 --- a/app/models/ci/persistent_ref.rb +++ b/app/models/ci/persistent_ref.rb @@ -15,13 +15,13 @@ module Ci def exist? ref_exists?(path) - rescue + rescue StandardError false end def create create_ref(sha, path) - rescue => e + rescue StandardError => e Gitlab::ErrorTracking .track_exception(e, pipeline_id: pipeline.id) end @@ -30,7 +30,7 @@ module Ci delete_refs(path) rescue Gitlab::Git::Repository::NoRepository # no-op - rescue => e + rescue StandardError => e Gitlab::ErrorTracking .track_exception(e, pipeline_id: pipeline.id) end diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 9dd75150ac7..7c5324a2181 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -46,7 +46,7 @@ module Ci self.position = statuses.select(:stage_idx) .where.not(stage_idx: nil) .group(:stage_idx) - .order('COUNT(*) DESC') + .order('COUNT(id) DESC') .first&.stage_idx.to_i end diff --git a/app/models/concerns/cacheable_attributes.rb b/app/models/concerns/cacheable_attributes.rb index ee56322cce7..f3b47047c55 100644 --- a/app/models/concerns/cacheable_attributes.rb +++ b/app/models/concerns/cacheable_attributes.rb @@ -53,7 +53,7 @@ module CacheableAttributes return cached_record if cached_record.present? current_without_cache.tap { |current_record| current_record&.cache! } - rescue => e + rescue StandardError => e if Rails.env.production? Gitlab::AppLogger.warn("Cached record for #{name} couldn't be loaded, falling back to uncached record: #{e}") else @@ -66,7 +66,7 @@ module CacheableAttributes def expire Gitlab::SafeRequestStore.delete(request_store_cache_key) cache_backend.delete(cache_key) - rescue + rescue StandardError # Gracefully handle when Redis is not available. For example, # omnibus may fail here during gitlab:assets:compile. end diff --git a/app/models/concerns/has_repository.rb b/app/models/concerns/has_repository.rb index 774cda2c3e8..33f6904bc91 100644 --- a/app/models/concerns/has_repository.rb +++ b/app/models/concerns/has_repository.rb @@ -17,7 +17,7 @@ module HasRepository def valid_repo? repository.exists? - rescue + rescue StandardError errors.add(:base, _('Invalid repository path')) false end @@ -25,7 +25,7 @@ module HasRepository def repo_exists? strong_memoize(:repo_exists) do repository.exists? - rescue + rescue StandardError false end end diff --git a/app/models/concerns/milestoneable.rb b/app/models/concerns/milestoneable.rb index d42417bb6c1..1d9fa2b9697 100644 --- a/app/models/concerns/milestoneable.rb +++ b/app/models/concerns/milestoneable.rb @@ -28,7 +28,7 @@ module Milestoneable scope :without_release, -> do joins("LEFT OUTER JOIN milestone_releases ON #{table_name}.milestone_id = milestone_releases.milestone_id") - .where('milestone_releases.release_id IS NULL') + .where(milestone_releases: { release_id: nil }) end scope :joins_milestone_releases, -> do diff --git a/app/models/concerns/repository_storage_movable.rb b/app/models/concerns/repository_storage_movable.rb index 8607f0d94f4..990d50eb073 100644 --- a/app/models/concerns/repository_storage_movable.rb +++ b/app/models/concerns/repository_storage_movable.rb @@ -50,7 +50,7 @@ module RepositoryStorageMovable begin storage_move.container.set_repository_read_only!(skip_git_transfer_check: true) - rescue => err + rescue StandardError => err storage_move.add_error(err.message) next false end diff --git a/app/models/concerns/sha256_attribute.rb b/app/models/concerns/sha256_attribute.rb index 9dfe1b77829..5c52236ab6d 100644 --- a/app/models/concerns/sha256_attribute.rb +++ b/app/models/concerns/sha256_attribute.rb @@ -33,7 +33,7 @@ module Sha256Attribute unless column.type == :binary raise ArgumentError.new("sha256_attribute #{name.inspect} is invalid since the column type is not :binary") end - rescue => error + rescue StandardError => error Gitlab::AppLogger.error "Sha256Attribute initialization: #{error.message}" raise end diff --git a/app/models/concerns/sha_attribute.rb b/app/models/concerns/sha_attribute.rb index cbac6a210c7..e2a78e11f99 100644 --- a/app/models/concerns/sha_attribute.rb +++ b/app/models/concerns/sha_attribute.rb @@ -26,7 +26,7 @@ module ShaAttribute unless column.type == :binary raise ArgumentError.new("sha_attribute #{name.inspect} is invalid since the column type is not :binary") end - rescue => error + rescue StandardError => error Gitlab::AppLogger.error "ShaAttribute initialization: #{error.message}" raise end diff --git a/app/models/concerns/storage/legacy_namespace.rb b/app/models/concerns/storage/legacy_namespace.rb index a82cf338039..743be9287ea 100644 --- a/app/models/concerns/storage/legacy_namespace.rb +++ b/app/models/concerns/storage/legacy_namespace.rb @@ -48,7 +48,7 @@ module Storage begin send_update_instructions write_projects_repository_config - rescue => e + rescue StandardError => e Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e, full_path_before_last_save: full_path_before_last_save, full_path: full_path, diff --git a/app/models/concerns/x509_serial_number_attribute.rb b/app/models/concerns/x509_serial_number_attribute.rb index d2a5c736604..1db693ce892 100644 --- a/app/models/concerns/x509_serial_number_attribute.rb +++ b/app/models/concerns/x509_serial_number_attribute.rb @@ -33,7 +33,7 @@ module X509SerialNumberAttribute unless column.type == :binary raise ArgumentError.new("x509_serial_number_attribute #{name.inspect} is invalid since the column type is not :binary") end - rescue => error + rescue StandardError => error Gitlab::AppLogger.error "X509SerialNumberAttribute initialization: #{error.message}" raise end diff --git a/app/models/deployment_merge_request.rb b/app/models/deployment_merge_request.rb index 7949bd81605..b91785eeb57 100644 --- a/app/models/deployment_merge_request.rb +++ b/app/models/deployment_merge_request.rb @@ -12,7 +12,7 @@ class DeploymentMergeRequest < ApplicationRecord end def self.by_deployment_id(id) - where('deployments.id = ?', id) + where(deployments: { id: id }) end def self.deployed_to(name) @@ -20,7 +20,7 @@ class DeploymentMergeRequest < ApplicationRecord # (project_id, name), instead of using the index on # (name varchar_pattern_ops). This results in better performance on # GitLab.com. - where('environments.name = ?', name) + where(environments: { name: name }) .where('environments.project_id = merge_requests.target_project_id') end diff --git a/app/models/design_management/version.rb b/app/models/design_management/version.rb index 5cfd8f3ec8e..68a0b8faf4f 100644 --- a/app/models/design_management/version.rb +++ b/app/models/design_management/version.rb @@ -94,7 +94,7 @@ module DesignManagement version end - rescue + rescue StandardError raise CouldNotCreateVersion.new(sha, issue_id, design_actions) end diff --git a/app/models/environment.rb b/app/models/environment.rb index 4ee93b0ba4a..6dff8e4f5f8 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -269,7 +269,7 @@ class Environment < ApplicationRecord Gitlab::OptimisticLocking.retry_lock(deployment.deployable, name: 'environment_cancel_deployment_jobs') do |deployable| deployable.cancel! if deployable&.cancelable? end - rescue => e + rescue StandardError => e Gitlab::ErrorTracking.track_exception(e, environment_id: id, deployment_id: deployment.id) end end diff --git a/app/models/group.rb b/app/models/group.rb index 60a0e27428d..77424fd116d 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -109,13 +109,13 @@ class Group < Namespace scope :for_authorized_group_members, -> (user_ids) do joins(:group_members) - .where("members.user_id IN (?)", user_ids) + .where(members: { user_id: user_ids }) .where("access_level >= ?", Gitlab::Access::GUEST) end scope :for_authorized_project_members, -> (user_ids) do joins(projects: :project_authorizations) - .where("project_authorizations.user_id IN (?)", user_ids) + .where(project_authorizations: { user_id: user_ids }) end class << self @@ -153,7 +153,7 @@ class Group < Namespace def select_for_project_authorization if current_scope.joins_values.include?(:shared_projects) joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id') - .where('project_namespace.share_with_group_lock = ?', false) + .where(project_namespace: { share_with_group_lock: false }) .select("projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level") else super diff --git a/app/models/hooks/web_hook_log.rb b/app/models/hooks/web_hook_log.rb index e2230a2d644..0c96d5d4b6d 100644 --- a/app/models/hooks/web_hook_log.rb +++ b/app/models/hooks/web_hook_log.rb @@ -5,9 +5,12 @@ class WebHookLog < ApplicationRecord include Presentable include DeleteWithLimit include CreatedAtFilterable + include PartitionedTable self.primary_key = :id + partitioned_by :created_at, strategy: :monthly + belongs_to :web_hook serialize :request_headers, Hash # rubocop:disable Cop/ActiveRecordSerialize diff --git a/app/models/hooks/web_hook_log_archived.rb b/app/models/hooks/web_hook_log_archived.rb new file mode 100644 index 00000000000..a1c8a44f5ba --- /dev/null +++ b/app/models/hooks/web_hook_log_archived.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# This model is not intended to be used. +# It is a temporary reference to the old non-partitioned +# web_hook_logs table. +# Please refer to https://gitlab.com/groups/gitlab-org/-/epics/5558 +# for details. +# rubocop:disable Gitlab/NamespacedClass: This is a temporary class with no relevant namespace +# WebHook, WebHookLog and all hooks are defined outside of a namespace +class WebHookLogArchived < ApplicationRecord + self.table_name = 'web_hook_logs_archived' +end diff --git a/app/models/hooks/web_hook_log_partitioned.rb b/app/models/hooks/web_hook_log_partitioned.rb deleted file mode 100644 index b4b150afb6a..00000000000 --- a/app/models/hooks/web_hook_log_partitioned.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -# This model is not yet intended to be used. -# It is in a transitioning phase while we are partitioning -# the web_hook_logs table on the database-side. -# Please refer to https://gitlab.com/groups/gitlab-org/-/epics/5558 -# for details. -# rubocop:disable Gitlab/NamespacedClass: This is a temporary class with no relevant namespace -# WebHook, WebHookLog and all hooks are defined outside of a namespace -class WebHookLogPartitioned < ApplicationRecord - include PartitionedTable - - self.table_name = 'web_hook_logs_part_0c5294f417' - self.primary_key = :id - - partitioned_by :created_at, strategy: :monthly -end diff --git a/app/models/issue.rb b/app/models/issue.rb index af78466e6a9..743e8417ced 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -87,7 +87,8 @@ class Issue < ApplicationRecord enum issue_type: { issue: 0, incident: 1, - test_case: 2 ## EE-only + test_case: 2, ## EE-only + requirement: 3 ## EE-only } alias_method :issuing_parent, :project diff --git a/app/models/issue_assignee.rb b/app/models/issue_assignee.rb index d62f0eb170c..1f7479d7b0a 100644 --- a/app/models/issue_assignee.rb +++ b/app/models/issue_assignee.rb @@ -8,7 +8,7 @@ class IssueAssignee < ApplicationRecord validates :assignee, uniqueness: { scope: :issue_id } - scope :in_projects, ->(project_ids) { joins(:issue).where("issues.project_id in (?)", project_ids) } + scope :in_projects, ->(project_ids) { joins(:issue).where(issues: { project_id: project_ids }) } scope :on_issues, ->(issue_ids) { where(issue_id: issue_ids) } scope :for_assignee, ->(user) { where(assignee: user) } end diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 9a86b3a3fd9..484237a6dec 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -16,7 +16,7 @@ class ProjectMember < Member scope :in_project, ->(project) { where(source_id: project.id) } scope :in_namespaces, ->(groups) do joins('INNER JOIN projects ON projects.id = members.source_id') - .where('projects.namespace_id in (?)', groups.select(:id)) + .where(projects: { namespace_id: groups.select(:id) }) end scope :without_project_bots, -> do @@ -69,7 +69,7 @@ class ProjectMember < Member end true - rescue + rescue StandardError false end diff --git a/app/models/merge_request_assignee.rb b/app/models/merge_request_assignee.rb index 73f8fe77b04..86bf950ae19 100644 --- a/app/models/merge_request_assignee.rb +++ b/app/models/merge_request_assignee.rb @@ -6,5 +6,5 @@ class MergeRequestAssignee < ApplicationRecord validates :assignee, uniqueness: { scope: :merge_request_id } - scope :in_projects, ->(project_ids) { joins(:merge_request).where("merge_requests.target_project_id in (?)", project_ids) } + scope :in_projects, ->(project_ids) { joins(:merge_request).where(merge_requests: { target_project_id: project_ids }) } end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 4cf0e423a15..0999ee5fd15 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -94,7 +94,7 @@ class Milestone < ApplicationRecord end def participants - User.joins(assigned_issues: :milestone).where("milestones.id = ?", id).distinct + User.joins(assigned_issues: :milestone).where(milestones: { id: id }).distinct end def self.sort_by_attribute(method) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 455429608b4..16e65aa0fe6 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -89,7 +89,7 @@ class Namespace < ApplicationRecord before_destroy(prepend: true) { prepare_for_destroy } after_destroy :rm_dir - scope :for_user, -> { where('type IS NULL') } + scope :for_user, -> { where(type: nil) } scope :sort_by_type, -> { order(Gitlab::Database.nulls_first_order(:type)) } scope :include_route, -> { includes(:route) } scope :by_parent, -> (parent) { where(parent_id: parent) } diff --git a/app/models/network/graph.rb b/app/models/network/graph.rb index 9da454125eb..560ff861105 100644 --- a/app/models/network/graph.rb +++ b/app/models/network/graph.rb @@ -27,7 +27,7 @@ module Network @project .notes - .where('noteable_type = ?', 'Commit') + .where(noteable_type: 'Commit') .group('notes.commit_id') .select('notes.commit_id, count(notes.id) as note_count') .each do |item| diff --git a/app/models/note.rb b/app/models/note.rb index 3e560a09fbd..13aa8fbfbd9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -319,7 +319,7 @@ class Note < ApplicationRecord return commit if for_commit? super - rescue + rescue StandardError # Temp fix to prevent app crash # if note commit id doesn't exist nil diff --git a/app/models/operations/feature_flag.rb b/app/models/operations/feature_flag.rb index be3f719ddb3..537543a7ff0 100644 --- a/app/models/operations/feature_flag.rb +++ b/app/models/operations/feature_flag.rb @@ -97,7 +97,7 @@ module Operations issues = ::Issue .select('issues.*, operations_feature_flags_issues.id AS link_id') .joins(:feature_flag_issues) - .where('operations_feature_flags_issues.feature_flag_id = ?', id) + .where(operations_feature_flags_issues: { feature_flag_id: id }) .order('operations_feature_flags_issues.id ASC') .includes(preload) diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb index ad2f4525171..6a786f75ec1 100644 --- a/app/models/personal_access_token.rb +++ b/app/models/personal_access_token.rb @@ -55,7 +55,7 @@ class PersonalAccessToken < ApplicationRecord begin Gitlab::CryptoHelper.aes256_gcm_decrypt(encrypted_token) - rescue => ex + rescue StandardError => ex logger.warn "Failed to decrypt #{self.name} value stored in Redis for key ##{redis_key}: #{ex.class}" encrypted_token end diff --git a/app/models/project.rb b/app/models/project.rb index f18d41e3556..44c32c53d90 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1097,7 +1097,7 @@ class Project < ApplicationRecord else super end - rescue + rescue StandardError super end @@ -1559,7 +1559,7 @@ class Project < ApplicationRecord repository.after_create true - rescue => err + rescue StandardError => err Gitlab::ErrorTracking.track_exception(err, project: { id: id, full_path: full_path, disk_path: disk_path }) errors.add(:base, _('Failed to create repository')) false diff --git a/app/models/project_services/asana_service.rb b/app/models/project_services/asana_service.rb index f31bf931a41..cd8e92f183c 100644 --- a/app/models/project_services/asana_service.rb +++ b/app/models/project_services/asana_service.rb @@ -98,7 +98,7 @@ class AsanaService < Service if tuple[0] task.update(completed: true) end - rescue => e + rescue StandardError => e log_error(e.message) next end diff --git a/app/models/project_services/external_wiki_service.rb b/app/models/project_services/external_wiki_service.rb index c41783d1af4..fa6ba13eb59 100644 --- a/app/models/project_services/external_wiki_service.rb +++ b/app/models/project_services/external_wiki_service.rb @@ -39,7 +39,7 @@ class ExternalWikiService < Service def execute(_data) response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true) response.body if response.code == 200 - rescue + rescue StandardError nil end diff --git a/app/models/project_services/irker_service.rb b/app/models/project_services/irker_service.rb index 4f1ce16ebb2..07b8b554ec0 100644 --- a/app/models/project_services/irker_service.rb +++ b/app/models/project_services/irker_service.rb @@ -103,7 +103,7 @@ class IrkerService < Service begin new_recipient = URI.join(default_irc_uri, '/', recipient).to_s uri = consider_uri(URI.parse(new_recipient)) - rescue + rescue StandardError log_error("Unable to create a valid URL", default_irc_uri: default_irc_uri, recipient: recipient) end end diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index 3e14bf44c12..7d8019d7027 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -305,7 +305,7 @@ class JiraService < IssueTrackerService ) true - rescue => error + rescue StandardError => error log_error( "Issue transition failed", error: { @@ -490,7 +490,7 @@ class JiraService < IssueTrackerService # Handle errors when doing Jira API calls def jira_request yield - rescue => error + rescue StandardError => error @error = error log_error("Error sending message", client_url: client_url, error: @error.message) nil diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 1a3f362e6a1..fa99e2cb1a7 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -130,7 +130,7 @@ class ProjectTeam end true - rescue + rescue StandardError false end diff --git a/app/models/release_highlight.rb b/app/models/release_highlight.rb index 98d9899a349..4b0ae251a9f 100644 --- a/app/models/release_highlight.rb +++ b/app/models/release_highlight.rb @@ -32,7 +32,7 @@ class ReleaseHighlight begin item.tap {|i| i['body'] = Kramdown::Document.new(i['body']).to_html } - rescue => e + rescue StandardError => e Gitlab::ErrorTracking.track_exception(e, file_path: file_path) next diff --git a/app/models/remote_mirror.rb b/app/models/remote_mirror.rb index c7387d2197d..1ba69aa9e4d 100644 --- a/app/models/remote_mirror.rb +++ b/app/models/remote_mirror.rb @@ -214,7 +214,7 @@ class RemoteMirror < ApplicationRecord if super Gitlab::UrlSanitizer.new(super, credentials: credentials).full_url end - rescue + rescue StandardError super end @@ -275,7 +275,7 @@ class RemoteMirror < ApplicationRecord return url unless ssh_key_auth? && password.present? Gitlab::UrlSanitizer.new(read_attribute(:url), credentials: { user: user }).full_url - rescue + rescue StandardError super end diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 5fdd4551982..fb3c190a637 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -118,7 +118,7 @@ class Snippet < ApplicationRecord def self.only_include_projects_visible_to(current_user = nil) levels = Gitlab::VisibilityLevel.levels_for_user(current_user) - joins(:project).where('projects.visibility_level IN (?)', levels) + joins(:project).where(projects: { visibility_level: levels }) end def self.only_include_projects_with_snippets_enabled(include_private: false) diff --git a/app/models/storage/legacy_project.rb b/app/models/storage/legacy_project.rb index f643d52587e..092e5249a3e 100644 --- a/app/models/storage/legacy_project.rb +++ b/app/models/storage/legacy_project.rb @@ -34,7 +34,7 @@ module Storage begin gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki") return true - rescue => e + rescue StandardError => e Gitlab::AppLogger.error("Exception renaming #{old_full_path} -> #{new_full_path}: #{e}") # Returning false does not rollback after_* transaction but gives # us information about failing some of tasks diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 089fc887d97..40527800783 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -88,7 +88,7 @@ class Wiki repository.create_if_not_exists raise CouldNotCreateWikiError unless repository_exists? - rescue => err + rescue StandardError => err Gitlab::ErrorTracking.track_exception(err, wiki: { container_type: container.class.name, container_id: container.id, |