Fixed issue #2345 - Elasticsearch payload is going too big if a ticket has more then 9000 articles.
This commit is contained in:
parent
fa60f25185
commit
2329a1c007
1 changed files with 23 additions and 16 deletions
|
@ -30,10 +30,12 @@ returns
|
|||
attachments_ignore = Setting.get('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
|
||||
|
||||
# max attachment size
|
||||
attachment_max_size_in_mb = Setting.get('es_attachment_max_size_in_mb') || 40
|
||||
attachment_max_size_in_mb = Setting.get('es_attachment_max_size_in_mb') || 10
|
||||
attachment_total_max_size_in_kb = 314_572
|
||||
attachment_total_max_size_in_kb_current = 0
|
||||
|
||||
# collect article data
|
||||
articles = Ticket::Article.where(ticket_id: id)
|
||||
articles = Ticket::Article.where(ticket_id: id).limit(1000)
|
||||
attributes['article'] = []
|
||||
articles.each do |article|
|
||||
|
||||
|
@ -53,6 +55,7 @@ returns
|
|||
|
||||
# lookup attachments
|
||||
article_attributes['attachment'] = []
|
||||
if attachment_total_max_size_in_kb_current < attachment_total_max_size_in_kb
|
||||
article.attachments.each do |attachment|
|
||||
|
||||
# check file size
|
||||
|
@ -67,12 +70,16 @@ returns
|
|||
|
||||
next if attachments_ignore.include?(filename_extention.downcase)
|
||||
|
||||
attachment_total_max_size_in_kb_current += (attachment.content.size / 1024).to_i
|
||||
next if attachment_total_max_size_in_kb_current > attachment_total_max_size_in_kb
|
||||
|
||||
data = {
|
||||
'_name' => attachment.filename,
|
||||
'_content' => Base64.encode64(attachment.content).delete("\n")
|
||||
}
|
||||
article_attributes['attachment'].push data
|
||||
end
|
||||
end
|
||||
attributes['article'].push article_attributes
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue