mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: Skip batches if all records exist
Update all import scripts to take advantage of all_records_exist?
This commit is contained in:
@ -194,6 +194,23 @@ class ImportScripts::Base
|
||||
g.tap(&:save)
|
||||
end
|
||||
|
||||
def all_records_exist?(type, import_ids)
|
||||
return false if import_ids.empty?
|
||||
|
||||
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
|
||||
|
||||
if Fixnum === import_ids.first
|
||||
existing = existing.where('cast(value as int) in (?)', import_ids)
|
||||
else
|
||||
existing = existing.where('value in (?)', import_ids)
|
||||
end
|
||||
|
||||
if existing.count == import_ids.length
|
||||
# puts "Skipping #{import_ids.length} already imported #{type}"
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# Iterate through a list of user records to be imported.
|
||||
# Takes a collection, and yields to the block for each element.
|
||||
# Block should return a hash with the attributes for the User model.
|
||||
|
Reference in New Issue
Block a user