mirror of
https://github.com/discourse/discourse.git
synced 2025-08-20 18:52:44 +08:00
keep uploads reverse index up to date
This commit is contained in:
parent
ae3543872c
commit
7bdc616040
4 changed files with 34 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue