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 8CD071FC0B for ; Tue, 31 Aug 2021 11:21:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 08/10] lei_mail_sync: set_src uses binary OIDs Date: Tue, 31 Aug 2021 11:21:24 +0000 Message-Id: <20210831112126.13406-9-e@80x24.org> In-Reply-To: <20210831112126.13406-1-e@80x24.org> References: <20210831112126.13406-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Another step towards moving more of our internals to use binary OIDs to avoid needless conversions before hitting disk. --- lib/PublicInbox/LeiMailSync.pm | 4 ++-- lib/PublicInbox/LeiStore.pm | 2 +- t/lei_mail_sync.t | 15 ++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index 275e0cc4..f8834a27 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -118,7 +118,7 @@ EOM } sub set_src { - my ($self, $oidhex, $folder, $id) = @_; + my ($self, $oidbin, $folder, $id) = @_; my $fid = $self->{fmap}->{$folder} //= fid_for($self, $folder, 1); my $sth; if (ref($id)) { # scalar name @@ -131,7 +131,7 @@ INSERT OR IGNORE INTO blob2name (oidbin, fid, name) VALUES (?, ?, ?) INSERT OR IGNORE INTO blob2num (oidbin, fid, uid) VALUES (?, ?, ?) } - $sth->execute(pack('H*', $oidhex), $fid, $id); + $sth->execute($oidbin, $fid, $id); } sub clear_src { diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 28e36e89..5a48c064 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -229,7 +229,7 @@ sub lms_rename_folder { sub set_sync_info { my ($self, $oidhex, $folder, $id) = @_; - _lms_rw($self)->set_src($oidhex, $folder, $id); + _lms_rw($self)->set_src(pack('H*', $oidhex), $folder, $id); } sub _remove_if_local { # git->cat_async arg diff --git a/t/lei_mail_sync.t b/t/lei_mail_sync.t index a5e5f5d3..5daa49cd 100644 --- a/t/lei_mail_sync.t +++ b/t/lei_mail_sync.t @@ -16,24 +16,25 @@ is_deeply([$ro->folders], [], 'no folders, yet'); my $imap = 'imaps://bob@[::1]/INBOX;UIDVALIDITY=9'; $lms->lms_begin; -is($lms->set_src('deadbeef', $imap, 1), 1, 'set IMAP once'); -ok($lms->set_src('deadbeef', $imap, 1) == 0, 'set IMAP idempotently'); +my $deadbeef = "\xde\xad\xbe\xef"; +is($lms->set_src($deadbeef, $imap, 1), 1, 'set IMAP once'); +ok($lms->set_src($deadbeef, $imap, 1) == 0, 'set IMAP idempotently'); $lms->lms_commit; is_deeply([$ro->folders], [$imap], 'IMAP folder added'); 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("\xde\xad\xbe\xef"), +is_deeply($ro->locations_for($deadbeef), { $imap => [ 1 ] }, 'locations_for w/ imap'); my $maildir = 'maildir:/home/user/md'; my $fname = 'foo:2,S'; $lms->lms_begin; -ok($lms->set_src('deadbeef', $maildir, \$fname), 'set Maildir once'); -ok($lms->set_src('deadbeef', $maildir, \$fname) == 0, 'set Maildir again'); +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("\xde\xad\xbe\xef"), +is_deeply($ro->locations_for($deadbeef), { $imap => [ 1 ], $maildir => [ $fname ] }, 'locations_for w/ maildir + imap'); @@ -45,7 +46,7 @@ if ('mess things up pretend old bug') { $lms->lms_commit; $lms->lms_begin; - ok($lms->set_src('deadbeef', $maildir, \$fname), 'set Maildir once'); + ok($lms->set_src($deadbeef, $maildir, \$fname), 'set Maildir once'); $lms->lms_commit; };