commit 9c6c6d3425358caf89c10097312cbe26d16059b6
parent 0b5f06e2c34d7aa986bfdcecc59d9fdf6650a88a
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Wed, 24 Mar 2010 21:27:45 -0700
factor each_source_info into Index
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -276,6 +276,14 @@ EOS
nil
end
+ ## Yields (in lexicographical order) the source infos of all locations from the given source
+ def each_source_info source_id, &b
+ prefix = mkterm :location, source_id, ''
+ each_prefixed_term prefix do |x|
+ yield x[prefix.length..-1]
+ end
+ end
+
class ParseError < StandardError; end
## parse a query string from the user. returns a query object
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -142,8 +142,7 @@ class MBox < Source
## TODO optimize this by iterating over allterms list backwards or
## storing source_info negated
def last_indexed_message
- prefix = "J#{[@id].pack('n')}" # XXX index internal
- Enumerator.new(Index, :each_prefixed_term, prefix).map { |x| x[prefix.length..-1].to_i }.max
+ Enumerator.new(Index, :each_source_info, self.id).map(&:to_i).max
end
## offset of first new message or nil