prep statement, use join to exclude existing
This commit is contained in:
@@ -65,16 +65,26 @@ class BlobEntrySampleExporter
|
||||
bind_nums = batch.size.times.map { |idx| "$#{idx + 1}" }
|
||||
|
||||
query = <<-SQL
|
||||
INSERT INTO blob_entries_p
|
||||
(
|
||||
SELECT sha256, base_sha256, content_type, size, contents, created_at
|
||||
FROM blob_entries
|
||||
WHERE sha256 IN (#{bind_nums.join(", ")})
|
||||
AND sha256 NOT IN (select sha256 from blob_entries_p)
|
||||
INSERT INTO blob_entries_p (
|
||||
SELECT
|
||||
be.sha256,
|
||||
be.base_sha256,
|
||||
be.content_type,
|
||||
be.size,
|
||||
be.contents,
|
||||
be.created_at
|
||||
FROM
|
||||
blob_entries be
|
||||
LEFT JOIN
|
||||
blob_entries_p bep ON be.sha256 = bep.sha256
|
||||
WHERE
|
||||
bep.sha256 IS NULL
|
||||
AND
|
||||
be.sha256 IN (#{bind_nums.join(", ")})
|
||||
) RETURNING sha256
|
||||
SQL
|
||||
|
||||
result = connection.exec_query query, "SQL", binds
|
||||
result = connection.exec_query query, "SQL", binds, prepare: true
|
||||
num_inserted = result.rows.length
|
||||
total_inserted += num_inserted
|
||||
num_inserted
|
||||
|
||||
Reference in New Issue
Block a user