From: Rich Lane Date: Sat, 22 Aug 2009 18:28:15 +0000 (-0700) Subject: add Message#load_from_index! shortcut X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=b633754b55d6d449dc87634c8e572dbfdb20e0b6;p=sup add Message#load_from_index! shortcut Message#parse_header is slow, taking up to 2/3 of the time spent loading threads in thread-index-mode. This patch adds a shortcut method that the index can use to efficiently initialize a message. --- diff --git a/lib/sup/message.rb b/lib/sup/message.rb index 7c63746..f31be0b 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -127,6 +127,31 @@ class Message @list_unsubscribe = header["list-unsubscribe"] end + ## Expected index entry format: + ## :message_id, :subject => String + ## :date => Time + ## :refs, :replytos => Array of String + ## :from => Person + ## :to, :cc, :bcc => Array of Person + def load_from_index! entry + @id = entry[:message_id] + @from = entry[:from] + @date = entry[:date] + @subj = entry[:subject] + @to = entry[:to] + @cc = entry[:cc] + @bcc = entry[:bcc] + @refs = (@refs + entry[:refs]).uniq + @replytos = entry[:replytos] + + @replyto = nil + @list_address = nil + @recipient_email = nil + @source_marked_read = false + @list_subscribe = nil + @list_unsubscribe = nil + end + def add_ref ref @refs << ref @dirty = true diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb index 87a5441..7e65a70 100644 --- a/lib/sup/xapian_index.rb +++ b/lib/sup/xapian_index.rb @@ -71,25 +71,17 @@ class XapianIndex < BaseIndex source = SourceManager[entry[:source_id]] raise "invalid source #{entry[:source_id]}" unless source - mk_addrs = lambda { |l| l.map { |e,n| "#{n} <#{e}>" } * ', ' } - mk_refs = lambda { |l| l.map { |r| "<#{r}>" } * ' ' } - fake_header = { - 'message-id' => entry[:message_id], - 'date' => Time.at(entry[:date]), - 'subject' => entry[:subject], - 'from' => mk_addrs[[entry[:from]]], - 'to' => mk_addrs[entry[:to]], - 'cc' => mk_addrs[entry[:cc]], - 'bcc' => mk_addrs[entry[:bcc]], - 'reply-tos' => mk_refs[entry[:replytos]], - 'references' => mk_refs[entry[:refs]], - } - - m = Message.new :source => source, :source_info => entry[:source_info], - :labels => entry[:labels], - :snippet => entry[:snippet] - m.parse_header fake_header - m + m = Message.new :source => source, :source_info => entry[:source_info], + :labels => entry[:labels], :snippet => entry[:snippet] + + mk_person = lambda { |x| Person.new(*x.reverse!) } + entry[:from] = mk_person[entry[:from]] + entry[:to].map!(&mk_person) + entry[:cc].map!(&mk_person) + entry[:bcc].map!(&mk_person) + + m.load_from_index! entry + m end def sync_message m, opts={}