From fb8f2799ff3bb1c95a539c0678f870acf64792db Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Sun, 9 Nov 2014 21:10:23 +0100 Subject: [PATCH] Increased performance on IMAP verify. --- app/models/channel/imap.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index a8114b338..5eb460697 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -37,9 +37,17 @@ class Channel::IMAP < Channel::EmailParser elsif check_type == 'verify' puts "verify mode, fetch no emails #{verify_string}" end - count = 0 - count_all = @imap.search(['ALL']).count - @imap.search(['ALL']).each do |message_id| + + message_ids = @imap.search(['ALL']) + count_all = message_ids.count + count = 0 + + # reverse message order to increase performance + if check_type == 'verify' + message_ids.reverse! + end + + message_ids.each do |message_id| count += 1 puts " - message #{count.to_s}/#{count_all.to_s}" # puts msg.to_s