mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
keep uploads reverse index up to date
This commit is contained in:
@@ -36,6 +36,8 @@ class CookedPostProcessor
|
||||
# retrieve the associated upload, if any
|
||||
upload = get_upload_from_url(img['src'])
|
||||
if upload.present?
|
||||
# update reverse index
|
||||
associate_to_post upload
|
||||
# create a thumbnail
|
||||
upload.create_thumbnail!
|
||||
# optimize image
|
||||
@@ -87,6 +89,13 @@ class CookedPostProcessor
|
||||
end
|
||||
end
|
||||
|
||||
def associate_to_post(upload)
|
||||
return if PostUpload.where(post_id: @post.id, upload_id: upload.id).count > 0
|
||||
PostUpload.create({ post_id: @post.id, upload_id: upload.id })
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# do not care if it's already associated
|
||||
end
|
||||
|
||||
def optimize_image(img)
|
||||
return img["src"]
|
||||
# 1) optimize using image_optim
|
||||
|
||||
Reference in New Issue
Block a user