mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:06:26 +08:00
FIX: Importing with pgbouncer failed
Checking if all records have been imported uses a temp table in PostgreSQL. This fails when pgbouncer is used unless the temp table is created inside a transaction.
This commit is contained in:
parent
c94b63bc75
commit
d216483c53
|
@ -219,24 +219,28 @@ class ImportScripts::Base
|
|||
def all_records_exist?(type, import_ids)
|
||||
return false if import_ids.empty?
|
||||
|
||||
connection = ActiveRecord::Base.connection.raw_connection
|
||||
connection.exec('CREATE TEMP TABLE import_ids(val text PRIMARY KEY)')
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
connection = ActiveRecord::Base.connection.raw_connection
|
||||
connection.exec('CREATE TEMP TABLE import_ids(val text PRIMARY KEY)')
|
||||
|
||||
import_id_clause = import_ids.map { |id| "('#{PG::Connection.escape_string(id.to_s)}')" }.join(",")
|
||||
import_id_clause = import_ids.map { |id| "('#{PG::Connection.escape_string(id.to_s)}')" }.join(",")
|
||||
|
||||
connection.exec("INSERT INTO import_ids VALUES #{import_id_clause}")
|
||||
connection.exec("INSERT INTO import_ids VALUES #{import_id_clause}")
|
||||
|
||||
existing = "#{type.to_s.classify}CustomField".constantize
|
||||
existing = existing.where(name: 'import_id')
|
||||
.joins('JOIN import_ids ON val = value')
|
||||
.count
|
||||
existing = "#{type.to_s.classify}CustomField".constantize
|
||||
existing = existing.where(name: 'import_id')
|
||||
.joins('JOIN import_ids ON val = value')
|
||||
.count
|
||||
|
||||
if existing == import_ids.length
|
||||
puts "Skipping #{import_ids.length} already imported #{type}"
|
||||
true
|
||||
if existing == import_ids.length
|
||||
puts "Skipping #{import_ids.length} already imported #{type}"
|
||||
true
|
||||
end
|
||||
ensure
|
||||
connection.exec('DROP TABLE import_ids') unless connection.nil?
|
||||
end
|
||||
end
|
||||
ensure
|
||||
connection.exec('DROP TABLE import_ids') unless connection.nil?
|
||||
end
|
||||
|
||||
def created_user(user)
|
||||
|
|
Loading…
Reference in New Issue
Block a user