X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2FPublicInbox%2FMbox.pm;h=0be1968584d9c68a7a76a72b98f82afea13bc564;hb=0dceebd0a85774c92af247e6da5e2f5a0ee8417c;hp=05de6be1a678f75ac258b24233c9f52d8c7a585f;hpb=b9534449ecce2c59bb4aebad6051f91c3116b187;p=public-inbox.git diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index 05de6be1..0be19685 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -138,8 +138,12 @@ sub thread_mbox { my ($ctx, $srch, $sfx) = @_; eval { require IO::Compress::Gzip }; return sub { need_gzip(@_) } if $@; - - my $cb = sub { $srch->get_thread($ctx->{mid}, @_) }; + my $prev = 0; + my $cb = sub { + my $msgs = $srch->get_thread($ctx->{mid}, $prev); + $prev = $msgs->[-1]->{num} if scalar(@$msgs); + $msgs; + }; PublicInbox::MboxGz->response($ctx, $cb); } @@ -160,7 +164,25 @@ sub mbox_all { eval { require IO::Compress::Gzip }; return sub { need_gzip(@_) } if $@; - my $cb = sub { $ctx->{srch}->query($query, @_) }; + if ($query eq '') { + my $prev = 0; + my $msgs = []; + my $cb = sub { + $ctx->{-inbox}->mm->id_batch($prev, sub { + $msgs = $_[0]; + }); + $prev = $msgs->[-1] if @$msgs; + $msgs; + }; + return PublicInbox::MboxGz->response($ctx, $cb, 'all'); + } + my $opts = { offset => 0 }; + my $srch = $ctx->{srch}; + my $cb = sub { # called by MboxGz->getline + my $msgs = $srch->query($query, $opts); + $opts->{offset} += scalar @$msgs; + $msgs; + }; PublicInbox::MboxGz->response($ctx, $cb, 'results-'.$query); } @@ -192,7 +214,6 @@ sub new { cb => $cb, ctx => $ctx, msgs => [], - opts => { offset => 0 }, }, $class; } @@ -223,6 +244,10 @@ sub getline { do { # work on existing result set while (defined(my $smsg = shift @$msgs)) { + # id_batch may return integers + ref($smsg) or + $smsg = $ctx->{srch}->{over_ro}->get_art($smsg); + my $msg = eval { $ibx->msg_by_smsg($smsg) } or next; $msg = Email::Simple->new($msg); $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg, @@ -247,10 +272,10 @@ sub getline { } # refill result set - $msgs = $self->{msgs} = $self->{cb}->($self->{opts}); - $self->{opts}->{offset} += scalar @$msgs; + $msgs = $self->{msgs} = $self->{cb}->(); } while (@$msgs); $gz->close; + # signal that we're done and can return undef next call: delete $self->{ctx}; ${delete $self->{buf}}; }