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' ]
|
attachments_ignore = Setting.get('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
|
||||||
|
|
||||||
# max attachment size
|
# 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
|
# collect article data
|
||||||
articles = Ticket::Article.where(ticket_id: id)
|
articles = Ticket::Article.where(ticket_id: id).limit(1000)
|
||||||
attributes['article'] = []
|
attributes['article'] = []
|
||||||
articles.each do |article|
|
articles.each do |article|
|
||||||
|
|
||||||
|
@ -53,6 +55,7 @@ returns
|
||||||
|
|
||||||
# lookup attachments
|
# lookup attachments
|
||||||
article_attributes['attachment'] = []
|
article_attributes['attachment'] = []
|
||||||
|
if attachment_total_max_size_in_kb_current < attachment_total_max_size_in_kb
|
||||||
article.attachments.each do |attachment|
|
article.attachments.each do |attachment|
|
||||||
|
|
||||||
# check file size
|
# check file size
|
||||||
|
@ -67,12 +70,16 @@ returns
|
||||||
|
|
||||||
next if attachments_ignore.include?(filename_extention.downcase)
|
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 = {
|
data = {
|
||||||
'_name' => attachment.filename,
|
'_name' => attachment.filename,
|
||||||
'_content' => Base64.encode64(attachment.content).delete("\n")
|
'_content' => Base64.encode64(attachment.content).delete("\n")
|
||||||
}
|
}
|
||||||
article_attributes['attachment'].push data
|
article_attributes['attachment'].push data
|
||||||
end
|
end
|
||||||
|
end
|
||||||
attributes['article'].push article_attributes
|
attributes['article'].push article_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue