Class: CustomerRelations::IssueContact
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CustomerRelations::IssueContact
- Includes:
- EachBatch
- Defined in:
- app/models/customer_relations/issue_contact.rb
Constant Summary collapse
- BATCH_DELETE_SIZE =
1_000
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .delete_for_group(group) ⇒ Object
- .delete_for_project(project_id) ⇒ Object
- .find_contact_ids_by_emails(issue_id, emails) ⇒ Object
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.delete_for_group(group) ⇒ Object
30 31 32 33 34 35 |
# File 'app/models/customer_relations/issue_contact.rb', line 30 def self.delete_for_group(group) loop do deleted_records = joins(issue: :project).where(projects: { namespace: group.self_and_descendants }).limit(BATCH_DELETE_SIZE).delete_all break if deleted_records == 0 end end |
.delete_for_project(project_id) ⇒ Object
23 24 25 26 27 28 |
# File 'app/models/customer_relations/issue_contact.rb', line 23 def self.delete_for_project(project_id) loop do deleted_records = joins(:issue).where(issues: { project_id: project_id }).limit(BATCH_DELETE_SIZE).delete_all break if deleted_records == 0 end end |
.find_contact_ids_by_emails(issue_id, emails) ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/models/customer_relations/issue_contact.rb', line 15 def self.find_contact_ids_by_emails(issue_id, emails) raise ArgumentError, "Cannot lookup more than #{MAX_PLUCK} emails" if emails.length > MAX_PLUCK joins(:contact) .where(issue_id: issue_id, customer_relations_contacts: { email: emails }) .pluck(:contact_id) end |