]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mail_sync: locations_for API uses oidbin for comparisons
authorEric Wong <e@80x24.org>
Sun, 25 Jul 2021 00:43:32 +0000 (00:43 +0000)
committerEric Wong <e@80x24.org>
Sun, 25 Jul 2021 06:14:06 +0000 (06:14 +0000)
Favor oidbin use internally to reduce internal memory traffic.

lib/PublicInbox/LeiInspect.pm
lib/PublicInbox/LeiMailSync.pm
t/lei_mail_sync.t

index c277520c03b44eeca3717112607964809f10bc2b..bf7a48368d318a2a493e9357ffeaaacd78e4a840 100644 (file)
@@ -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;
                }
        }
index 49e521da7e8ad6edd67c7b51f7cad09ae5fdd2fe..82740d59b69c42e84d94dfa0faf4be2f1182bc4a 100644 (file)
@@ -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;
index f0605092fa6e70f40b187e36d269f0e245d3a6b5..a5e5f5d30a0062b03cbe5b508914b889469a10a8 100644 (file)
@@ -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');