From: William Morgan Date: Wed, 20 Feb 2008 22:38:00 +0000 (-0800) Subject: share Ferret entry information on state updates, when possible X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=615cfcc67a858e7c707c777cb5a00b7ffe31f6e8;p=sup share Ferret entry information on state updates, when possible --- diff --git a/lib/sup/index.rb b/lib/sup/index.rb index a7e48f6..38d4e1f 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -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