From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.42.229.71 with SMTP id jh7cs147143icb; Tue, 18 Jan 2011 11:25:44 -0800 (PST) Received: by 10.150.219.10 with SMTP id r10mr1443770ybg.318.1295378743592; Tue, 18 Jan 2011 11:25:43 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id m12si9395260qcu.183.2011.01.18.11.25.43; Tue, 18 Jan 2011 11:25:43 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id E200F1678327; Tue, 18 Jan 2011 14:25:42 -0500 (EST) Received: from smtp.chost.de (setoy.chost.de [217.160.209.225]) by rubyforge.org (Postfix) with ESMTP id 2294A1858344 for ; Tue, 18 Jan 2011 13:26:22 -0500 (EST) Received: (qmail 30066 invoked by uid 5015); 18 Jan 2011 18:26:30 -0000 Received: (nullmailer pid 31466 invoked by uid 8193); Tue, 18 Jan 2011 18:26:21 -0000 Received: (nullmailer pid 2381 invoked by uid 8193); Tue, 18 Jan 2011 18:26:18 -0000 From: Sascha Silbe To: sup-devel Date: Tue, 18 Jan 2011 19:26:17 +0100 Message-Id: <1295375177-2342-1-git-send-email-sascha-pgp@silbe.org> X-Mailer: git-send-email 1.7.2.3 Mail-Followup-To: Subject: [sup-devel] [PATCH] pre-expand source URIs X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sascha Silbe , Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org 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 --- 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