sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 2e7a82db9d53a37dd55d2f2842b72aa0737afdce
parent e8b3e6ed08d982d15b22d6e35caae1f15682cae5
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed, 20 Feb 2008 20:59:30 -0800

Merge branch 'speedy-index' into next

Diffstat:
M lib/sup/index.rb | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -145,7 +145,7 @@ EOS
       field_infos.add_field :source_id
       field_infos.add_field :source_info
       field_infos.add_field :date, :index => :untokenized
-      field_infos.add_field :body, :store => :no
+      field_infos.add_field :body
       field_infos.add_field :label
       field_infos.add_field :subject
       field_infos.add_field :from
@@ -174,7 +174,6 @@ EOS
         m.source.id or raise "unregistered source #{m.source} (id #{m.source.id.inspect})"
       end
 
-    to = (m.to + m.cc + m.bcc).map { |x| x.email }.join(" ")
     snippet = 
       if m.snippet_contains_encrypted_content? && $config[:discard_snippets_from_encrypted_messages]
         ""
@@ -182,18 +181,27 @@ EOS
         m.snippet
       end
 
-    d = {
-      :message_id => m.id,
-      :source_id => source_id,
-      :source_info => m.source_info,
-      :date => m.date.to_indexable_s,
-      :body => m.indexable_content,
-      :snippet => snippet,
-      :label => m.labels.uniq.join(" "),
-      :from => m.from ? m.from.indexable_content : "",
-      :to => (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" "),
-      :subject => wrap_subj(m.subj),
-      :refs => (m.refs + m.replytos).uniq.join(" "),
+    ## write the new document to the index. if the entry already exists in the
+    ## index, reuse it (which avoids having to reload the entry from the source,
+    ## which can be quite expensive for e.g. large threads of IMAP actions.)
+    ##
+    ## written in this manner to support previous versions of the index which
+    ## did not keep around the entry body. upgrading is thus seamless.
+
+    entry ||= {}
+    d =
+    {
+      :message_id => (entry[:message_id] || m.id),
+      :source_id => (entry[:source_id] || source_id),
+      :source_info => (entry[:source_info] || m.source_info),
+      :date => (entry[:date] || m.date.to_indexable_s),
+      :body => (entry[:body] || m.indexable_content),
+      :snippet => snippet, # always override
+      :label => m.labels.uniq.join(" "), # always override
+      :from => (entry[:from] || (m.from ? m.from.indexable_content : "")),
+      :to => (entry[:to] || (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" ")),
+      :subject => (entry[:subject] || wrap_subj(m.subj)),
+      :refs => (entry[:refs] || (m.refs + m.replytos).uniq.join(" ")),
     }
 
     @index.delete docid if docid