Expand the URI for each source resp. each CLI argument only once. This brings down the time taken by sup-sync for parsing source arguments from 45s to less than 2 seconds for a list of 13 sources on my XO-1.5.
Signed-off-by: Sascha Silbe <sascha-...@silbe.org> --- lib/sup/maildir.rb | 5 +++-- lib/sup/mbox.rb | 6 ++++-- lib/sup/source.rb | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb index def2ac3..0c3061c 100644 --- a/lib/sup/maildir.rb +++ b/lib/sup/maildir.rb @@ -10,7 +10,8 @@ class Maildir < Source yaml_properties :uri, :usual, :archived, :id, :labels def initialize uri, usual=true, archived=false, id=nil, labels=[] super uri, usual, archived, id - uri = URI(Source.expand_filesystem_uri(uri)) + @expanded_uri = Source.expand_filesystem_uri(uri) + uri = URI(@expanded_uri) raise ArgumentError, "not a maildir URI" unless uri.scheme == "maildir" raise ArgumentError, "maildir URI cannot have a host: #{uri.host}" if uri.host @@ -24,7 +25,7 @@ class Maildir < Source def file_path; @dir end def self.suggest_labels_for path; [] end - def is_source_for? uri; super || (URI(Source.expand_filesystem_uri(uri)) == URI(self.uri)); end + def is_source_for? uri; super || (uri == @expanded_uri); end def store_message date, from_email, &block stored = false diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb index 2806cb3..af118c3 100644 --- a/lib/sup/mbox.rb +++ b/lib/sup/mbox.rb @@ -18,7 +18,8 @@ class MBox < Source case uri_or_fp when String - uri = URI(Source.expand_filesystem_uri(uri_or_fp)) + @expanded_uri = Source.expand_filesystem_uri(uri_or_fp) + uri = URI(@expanded_uri) raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox" raise ArgumentError, "mbox URI ('#{uri}') cannot have a host: #{uri.host}" if uri.host raise ArgumentError, "mbox URI must have a path component" unless uri.path @@ -27,13 +28,14 @@ class MBox < Source else @f = uri_or_fp @path = uri_or_fp.path + @expanded_uri = "mbox://#{@path}" end super uri_or_fp, usual, archived, id end def file_path; @path end - def is_source_for? uri; super || (self.uri.is_a?(String) && (URI(Source.expand_filesystem_uri(uri)) == URI(Source.expand_filesystem_uri(self.uri)))) end + def is_source_for? uri; super || (uri == @expanded_uri) end def self.suggest_labels_for path ## heuristic: use the filename as a label, unless the file diff --git a/lib/sup/source.rb b/lib/sup/source.rb index 204ebd5..9c398f7 100644 --- a/lib/sup/source.rb +++ b/lib/sup/source.rb @@ -193,7 +193,11 @@ class SourceManager @source_mutex.synchronize { @sources.values }.sort_by { |s| s.id }.partition { |s| !s.archived? }.flatten end - def source_for uri; sources.find { |s| s.is_source_for? uri }; end + def source_for uri + expanded_uri = Source.expand_filesystem_uri(uri) + sources.find { |s| s.is_source_for? expanded_uri } + end + def usual_sources; sources.find_all { |s| s.usual? }; end def unusual_sources; sources.find_all { |s| !s.usual? }; end -- 1.7.2.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel