Module: SupplejackApi::Support::Harvestable::ClassMethods

Defined in:
app/models/supplejack_api/support/harvestable.rb

Instance Method Summary collapse

Instance Method Details

#find_or_initialize_by_identifier(attributes) ⇒ Object



78
79
80
81
82
83
# File 'app/models/supplejack_api/support/harvestable.rb', line 78

def find_or_initialize_by_identifier(attributes)
  attributes = attributes.symbolize_keys
  identifier = attributes.delete(:internal_identifier)
  identifier = identifier.first if identifier.is_a?(Array)
  find_or_initialize_by(internal_identifier: identifier)
end

#flush_old_records(source_id, job_id) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/supplejack_api/support/harvestable.rb', line 85

def flush_old_records(source_id, job_id)
  where(
    :'fragments.source_id' => source_id,
    :'fragments.job_id'.ne => job_id,
    :status.in => %w(active supressed)
  ).update_all(status: 'deleted', updated_at: Time.now)

  cursor = deleted.where('fragments.source_id': source_id)
  total = cursor.count
  start = 0
  chunk_size = 10_000
  while start < total
    records = cursor.limit(chunk_size).skip(start)
    Sunspot.remove(records)
    start += chunk_size
  end
end