]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q: trim JSON output
authorEric Wong <e@80x24.org>
Sat, 20 Mar 2021 12:40:31 +0000 (18:40 +0600)
committerEric Wong <e@80x24.org>
Sun, 21 Mar 2021 09:46:51 +0000 (09:46 +0000)
Stop showing `docid' since it's not useful with shards.

`bytes' and `lines' are probably noise, but maybe could be
visible in some "fuller" view.

v2: t/lei_xsearch: fix warnings from {docid} removal

lib/PublicInbox/LeiOverview.pm
lib/PublicInbox/LeiXSearch.pm
t/lei-import.t
t/lei_xsearch.t

index 521bca502a86fdf98275db71abe1fca3d4d3fa06..1ce2a09878329645499e91be4c8e9a429c0f4d08 100644 (file)
@@ -136,7 +136,10 @@ sub ovv_end {
 sub _unbless_smsg {
        my ($smsg, $mitem) = @_;
 
-       delete @$smsg{qw(lines bytes num tid)};
+       # TODO: make configurable
+       # num/tid are nonsensical with multi-inbox search,
+       # lines/bytes are not generally useful
+       delete @$smsg{qw(num tid lines bytes)};
        $smsg->{rt} = _iso8601(delete $smsg->{ts}); # JMAP receivedAt
        $smsg->{dt} = _iso8601(delete $smsg->{ds}); # JMAP UTCDate
        $smsg->{pct} = get_pct($mitem) if $mitem;
@@ -151,7 +154,8 @@ sub _unbless_smsg {
                $smsg->{substr($f, 0, 1)} = pairs($v);
        }
        $smsg->{'s'} = delete $smsg->{subject};
-       scalar { %$smsg }; # unbless
+       my $kw = delete($smsg->{kw});
+       scalar { %$smsg, ($kw && scalar(@$kw) ? (kw => $kw) : ()) }; # unbless
 }
 
 sub ovv_atexit_child {
index 57717b8751eae5cc74555a2cef5b03be29ebbadf..17171a7fd446bbd57d3296584d3a74c4a0b83b67 100644 (file)
@@ -70,6 +70,8 @@ sub mitem_kw ($$;$) {
        my ($smsg, $mitem, $flagged) = @_;
        my $kw = xap_terms('K', $mitem->get_document);
        $kw->{flagged} = 1 if $flagged;
+       # we keep the empty array here to prevent expensive work in
+       # ->xsmsg_vmd, _unbless_smsg will clobber it iff it's empty
        $smsg->{kw} = [ sort keys %$kw ];
 }
 
@@ -85,7 +87,6 @@ sub smsg_for {
        my $smsg = $ibx->over->get_art($num);
        return if $smsg->{bytes} == 0;
        mitem_kw($smsg, $mitem) if $ibx->can('msg_keywords');
-       $smsg->{docid} = $docid;
        $smsg;
 }
 
index edb0cd206f8f63b86f8977f0a248c406f78f58fe..e0b517f4d2f41bc36b91a72308795c8955e7471f 100644 (file)
@@ -48,7 +48,7 @@ lei_ok([qw(import --no-kw -F eml -)], undef, $opt,
 lei(qw(q m:v@y));
 $res = json_utf8->decode($lei_out);
 is($res->[1], undef, 'only one result');
-is_deeply($res->[0]->{kw}, [], 'no keywords set');
+is($res->[0]->{kw}, undef, 'no keywords set');
 
 # see t/lei_to_mail.t for "import -F mbox*"
 });
index e56b28204ca13f1e0fb616a0c2c60f24d48798e1..3eb442338ddc4dd8b919b5e60a56aab126284a91 100644 (file)
@@ -3,7 +3,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
-use List::Util qw(shuffle max);
+use List::Util qw(shuffle);
 use PublicInbox::TestCommon;
 use PublicInbox::Eml;
 require_mods(qw(DBD::SQLite Search::Xapian));
@@ -62,9 +62,6 @@ is(scalar(@msgs), $nr, 'smsgs retrieved for all');
 
 $mset = $lxs->recent(undef, { limit => 1 });
 is($mset->size, 1, 'one result');
-my $max = max(map { $_->{docid} } @msgs);
-is($lxs->smsg_for(($mset->items)[0])->{docid}, $max,
-       'got highest docid');
 
 my @ibxish = $lxs->locals;
 is(scalar(@ibxish), scalar(@ibx) + 1, 'got locals back');