sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 9c79d3bb94a790633a1342c2ccaa10bfc406fc29
parent 67dc1ab6be5095e07bd1ee24487763c342587a2a
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sat,  3 Apr 2010 10:01:06 -0700

simplify and benchmark MBox#last_indexed_message

Diffstat:
M lib/sup/maildir.rb | 4 ++--
M lib/sup/mbox.rb | 7 +------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -94,8 +94,8 @@ class Maildir < Source
       next if prev_mtime >= mtime
       @mtimes[d] = mtime
 
-      old_ids = benchmark(:index) { Enumerator.new(Index.instance, :each_source_info, self.id, "#{d}/").to_a }
-      new_ids = benchmark(:glob) { Dir.glob("#{subdir}/*").map { |x| File.basename x }.sort }
+      old_ids = benchmark(:maildir_read_index) { Enumerator.new(Index.instance, :each_source_info, self.id, "#{d}/").to_a }
+      new_ids = benchmark(:maildir_read_dir) { Dir.glob("#{subdir}/*").map { |x| File.basename x }.sort }
       added = new_ids - old_ids
       deleted = old_ids - new_ids
       debug "#{added.size} added, #{deleted.size} deleted"
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -145,12 +145,7 @@ class MBox < Source
   ## TODO optimize this by iterating over allterms list backwards or
   ## storing source_info negated
   def last_indexed_message
-    max = nil
-    Index.each_source_info(self.id) do |x|
-      x = x.to_i
-      max = x if !max || x > max
-    end
-    max
+    benchmark(:mbox_read_index) { Enumerator.new(Index.instance, :each_source_info, self.id).map(&:to_i).max }
   end
 
   ## offset of first new message or nil