sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 8f71da274b22b93654167166bf2447df45064b71
parent a0f3184058d499fe767425e44269319dcf9ff600
Author: Sascha Silbe <sascha-pgp@silbe.org>
Date:   Tue, 18 Jan 2011 19:26:17 +0100

pre-expand source URIs

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 

Diffstat:
M lib/sup/maildir.rb | 5 +++--
M lib/sup/mbox.rb | 6 ++++--
M lib/sup/source.rb | 6 +++++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git 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
@@ -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
@@ -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