Skip to content

Commit

Permalink
optimize large files upload
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jun 16, 2024
1 parent 009e055 commit 781ccc7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/templates/process_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module ProcessDocument
MAX_WIDTH = 1400
MAX_NUMBER_OF_PAGES_PROCESSED = 15
MAX_FLATTEN_FILE_SIZE = 15.megabytes
GENERATE_PREVIEW_SIZE_LIMIT = 50.megabytes

module_function

Expand Down Expand Up @@ -55,7 +56,9 @@ def generate_pdf_preview_images(attachment, data)

attachment.save!

(0..[number_of_pages - 1, MAX_NUMBER_OF_PAGES_PROCESSED].min).each do |page_number|
max_pages_to_process = data.size < GENERATE_PREVIEW_SIZE_LIMIT ? MAX_NUMBER_OF_PAGES_PROCESSED : 1

(0..[number_of_pages - 1, max_pages_to_process].min).each do |page_number|
page = Vips::Image.new_from_buffer(data, '', dpi: DPI, page: page_number)
page = page.resize(MAX_WIDTH / page.width.to_f)

Expand Down

0 comments on commit 781ccc7

Please sign in to comment.