]> git.cworth.org Git - sup/commitdiff
per-source short-circuit in sup-sync-back if there are no relevant messages
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 7 Jul 2007 14:30:49 +0000 (14:30 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 7 Jul 2007 14:30:49 +0000 (14:30 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@480 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup-sync-back
lib/sup/index.rb

index d61f219a09e428ee27d90283ab4133f15e8bdd4b..808f10f4f50df34644af4b76665af8de61b66090 100644 (file)
@@ -66,6 +66,12 @@ begin
   
   sources.each do |source|
     $stderr.puts "Scanning #{source}..."
+
+    unless ((opts[:delete_deleted] || opts[:move_deleted]) && index.has_any_from_source_with_label?(source, :deleted)) || ((opts[:delete_spam] || opts[:move_spam]) && index.has_any_from_source_with_label?(source, :spam))
+      $stderr.puts "Nothing to do from this source; skipping"
+      next
+    end
+
     source.reset!
     num_deleted = num_moved = num_scanned = 0
     
index 9ce4858374d4f9e08cfcc067f164ebca3f23602e..330b8a00f4035be95f34876b6ac2d059caf45787 100644 (file)
@@ -350,6 +350,13 @@ EOS
     @sources_dirty = false
   end
 
+  def has_any_from_source_with_label? source, label
+    q = Ferret::Search::BooleanQuery.new
+    q.add_query Ferret::Search::TermQuery.new("source_id", source.id.to_s), :must
+    q.add_query Ferret::Search::TermQuery.new("label", label.to_s), :must
+    num_results_for(:qobj => q) > 0
+  end
+
 protected
 
   def parse_user_query_string str; @qparser.parse str; end