]> git.notmuchmail.org Git - sup/commitdiff
share Ferret entry information on state updates, when possible
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 20 Feb 2008 22:38:00 +0000 (14:38 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 20 Feb 2008 22:39:41 +0000 (14:39 -0800)
lib/sup/index.rb

index a7e48f6d06e0e8934ce30aa04d3129769b02fcb7..38d4e1f0672bef9409d60e9e952f37f9703067b2 100644 (file)
@@ -181,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