mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 23:50:11 +08:00
FIX: concurrency bug when creating topic thumbnails
We were failing erratically when backfilling topic thumbnails. This ensures that racing threads/processes will not conflict.
This commit is contained in:
parent
2211581a85
commit
337bd9a0f7
|
@ -21,7 +21,19 @@ class TopicThumbnail < ActiveRecord::Base
|
|||
optimized = OptimizedImage.create_for(original, target_width, target_height)
|
||||
end
|
||||
|
||||
create!(upload: original, max_width: max_width, max_height: max_height, optimized_image: optimized)
|
||||
# may have been associated already, bulk insert will skip dupes
|
||||
TopicThumbnail.insert_all([
|
||||
upload_id: original.id,
|
||||
max_width: max_width,
|
||||
max_height: max_height,
|
||||
optimized_image_id: optimized.id
|
||||
])
|
||||
|
||||
TopicThumbnail.find_by(
|
||||
upload: original,
|
||||
max_width: max_width,
|
||||
max_height: max_height
|
||||
)
|
||||
end
|
||||
|
||||
def self.ensure_consistency!
|
||||
|
|
Loading…
Reference in New Issue
Block a user