From e24ea497cf4f86f0e6b99e3333b39aeb0f71c11f Mon Sep 17 00:00:00 2001 From: William Morgan Date: Sun, 26 Apr 2009 18:16:48 -0400 Subject: [PATCH] make Index#sync_message take an extra speedy arg Previously it would check the index if docid and entry were nil, even though nil is a valid result of a previous check. Add an extra argument controlling whether this check is performed again. Results in a minor speedup. --- lib/sup/index.rb | 34 +++++++++++++++++----------------- lib/sup/poll.rb | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index 29b26d3..725dda6 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -177,31 +177,31 @@ EOS end end - ## Syncs the message to the index: deleting if it's already there, - ## and adding either way. Index state will be determined by m.labels. + ## Syncs the message to the index, replacing any previous version. adding + ## either way. Index state will be determined by the message's #labels + ## accessor. ## - ## docid and entry can be specified if they're already known. - def sync_message m, docid=nil, entry=nil, opts={} - docid, entry = load_entry_for_id m.id unless docid && entry + ## if need_load is false, docid and entry are assumed to be set to the + ## result of load_entry_for_id (which can be nil). + def sync_message m, need_load=true, docid=nil, entry=nil, opts={} + docid, entry = load_entry_for_id m.id if need_load raise "no source info for message #{m.id}" unless m.source && m.source_info @index_mutex.synchronize do raise "trying to delete non-corresponding entry #{docid} with index message-id #{@index[docid][:message_id].inspect} and parameter message id #{m.id.inspect}" if docid && @index[docid][:message_id] != m.id end - source_id = - if m.source.is_a? Integer - m.source - else - m.source.id or raise "unregistered source #{m.source} (id #{m.source.id.inspect})" - end + source_id = if m.source.is_a? Integer + m.source + else + m.source.id or raise "unregistered source #{m.source} (id #{m.source.id.inspect})" + end - snippet = - if m.snippet_contains_encrypted_content? && $config[:discard_snippets_from_encrypted_messages] - "" - else - m.snippet - end + snippet = if m.snippet_contains_encrypted_content? && $config[:discard_snippets_from_encrypted_messages] + "" + else + m.snippet + end ## 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, diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb index d766587..afda64f 100644 --- a/lib/sup/poll.rb +++ b/lib/sup/poll.rb @@ -157,7 +157,7 @@ EOS docid, entry = Index.load_entry_for_id m.id HookManager.run "before-add-message", :message => m m = yield(m, offset, entry) or next if block_given? - Index.sync_message m, docid, entry, opts + times = Index.sync_message m, false, docid, entry, opts UpdateManager.relay self, :added, m unless entry rescue MessageFormatError => e Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}" -- 2.45.2