From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7E96A1FA13 for ; Sun, 25 Jul 2021 00:43:33 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/4] lei_mail_sync: locations_for API uses oidbin for comparisons Date: Sun, 25 Jul 2021 00:43:32 +0000 Message-Id: <20210725004332.23896-5-e@80x24.org> In-Reply-To: <20210725004332.23896-1-e@80x24.org> References: <20210725004332.23896-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Favor oidbin use internally to reduce internal memory traffic. --- lib/PublicInbox/LeiInspect.pm | 5 +++-- lib/PublicInbox/LeiMailSync.pm | 7 ++++--- t/lei_mail_sync.t | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index c277520c..bf7a4836 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -14,10 +14,11 @@ sub inspect_blob ($$) { my ($lei, $oidhex) = @_; my $ent = {}; if (my $lse = $lei->{lse}) { - my @docids = $lse ? $lse->over->blob_exists($oidhex) : (); + my $oidbin = pack('H*', $oidhex); + my @docids = $lse ? $lse->over->oidbin_exists($oidbin) : (); $ent->{'lei/store'} = \@docids if @docids; my $lms = $lse->lms; - if (my $loc = $lms ? $lms->locations_for($oidhex) : undef) { + if (my $loc = $lms ? $lms->locations_for($oidbin) : undef) { $ent->{'mail-sync'} = $loc; } } diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index 49e521da..82740d59 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -206,16 +206,16 @@ SELECT $op(uid) FROM blob2num WHERE fid = ? # returns a { location => [ list-of-ids-or-names ] } mapping sub locations_for { - my ($self, $oidhex) = @_; + my ($self, $oidbin) = @_; my ($fid, $sth, $id, %fid2id); my $dbh = $self->{dbh} //= dbh_new($self); $sth = $dbh->prepare('SELECT fid,uid FROM blob2num WHERE oidbin = ?'); - $sth->execute(pack('H*', $oidhex)); + $sth->execute($oidbin); while (my ($fid, $uid) = $sth->fetchrow_array) { push @{$fid2id{$fid}}, $uid; } $sth = $dbh->prepare('SELECT fid,name FROM blob2name WHERE oidbin = ?'); - $sth->execute(pack('H*', $oidhex)); + $sth->execute($oidbin); while (my ($fid, $name) = $sth->fetchrow_array) { push @{$fid2id{$fid}}, $name; } @@ -225,6 +225,7 @@ sub locations_for { $sth->execute($fid); my ($loc) = $sth->fetchrow_array; unless (defined $loc) { + my $oidhex = unpack('H*', $oidbin); warn "E: fid=$fid for $oidhex unknown:\n", map { 'E: '.(ref() ? $$_ : "#$_")."\n"; } @$ids; diff --git a/t/lei_mail_sync.t b/t/lei_mail_sync.t index f0605092..a5e5f5d3 100644 --- a/t/lei_mail_sync.t +++ b/t/lei_mail_sync.t @@ -24,7 +24,7 @@ is_deeply([$ro->folders($imap)], [$imap], 'IMAP folder with full GLOB'); is_deeply([$ro->folders('imaps://bob@[::1]/INBOX')], [$imap], 'IMAP folder with partial GLOB'); -is_deeply($ro->locations_for('deadbeef'), +is_deeply($ro->locations_for("\xde\xad\xbe\xef"), { $imap => [ 1 ] }, 'locations_for w/ imap'); my $maildir = 'maildir:/home/user/md'; @@ -33,7 +33,7 @@ $lms->lms_begin; ok($lms->set_src('deadbeef', $maildir, \$fname), 'set Maildir once'); ok($lms->set_src('deadbeef', $maildir, \$fname) == 0, 'set Maildir again'); $lms->lms_commit; -is_deeply($ro->locations_for('deadbeef'), +is_deeply($ro->locations_for("\xde\xad\xbe\xef"), { $imap => [ 1 ], $maildir => [ $fname ] }, 'locations_for w/ maildir + imap');