sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit ee375737de02cda87bdcba3a585a8d38d9223e2d
parent 846b146017002680ee95af5d7d6bb547e7fd7442
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sat, 20 Jun 2009 13:50:05 -0700

index: move has_any_from_source_with_label? to sup-sync-back

Diffstat:
M bin/sup-sync-back | 7 ++++++-
M lib/sup/index.rb | 7 -------
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/bin/sup-sync-back b/bin/sup-sync-back
@@ -4,6 +4,7 @@ require 'rubygems'
 require 'uri'
 require 'tempfile'
 require 'trollop'
+require 'enumerator'
 require "sup"
 
 ## save a message 'm' to an open file pointer 'fp'
@@ -14,6 +15,10 @@ def die msg
   $stderr.puts "Error: #{msg}"
   exit(-1)
 end
+def has_any_from_source_with_label? index, source, label
+  query = { :source_id => source.id, :label => label, :limit => 1 }
+  not Enumerable::Enumerator.new(index, :each_docid, query).map.empty?
+end
 
 opts = Trollop::options do
   version "sup-sync-back (sup #{Redwood::VERSION})"
@@ -96,7 +101,7 @@ EOS
   sources.each do |source|
     $stderr.puts "Scanning #{source}..."
 
-    unless ((opts[:drop_deleted] || opts[:move_deleted]) && index.has_any_from_source_with_label?(source, :deleted)) || ((opts[:drop_spam] || opts[:move_spam]) && index.has_any_from_source_with_label?(source, :spam))
+    unless ((opts[:drop_deleted] || opts[:move_deleted]) && has_any_from_source_with_label?(index, source, :deleted)) || ((opts[:drop_spam] || opts[:move_spam]) && has_any_from_source_with_label?(index, source, :spam))
       $stderr.puts "Nothing to do from this source; skipping"
       next
     end
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -450,13 +450,6 @@ EOS
     end
   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
-    @index_mutex.synchronize { @index.search(q, :limit => 1).total_hits > 0 }
-  end
-
   def each_docid query={}
     ferret_query = build_ferret_query query
     results = @index_mutex.synchronize { @index.search ferret_query, :limit => (query[:limit] || :all) }