user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/4] lei_mail_sync: locations_for API uses oidbin for comparisons
  2021-07-25  0:43  7% [PATCH 0/4] favor shorter binary OID comparisons Eric Wong
@ 2021-07-25  0:43  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-07-25  0:43 UTC (permalink / raw)
  To: meta

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');
 

^ permalink raw reply related	[relevance 6%]

* [PATCH 0/4] favor shorter binary OID comparisons
@ 2021-07-25  0:43  7% Eric Wong
  2021-07-25  0:43  6% ` [PATCH 4/4] lei_mail_sync: locations_for API uses oidbin for comparisons Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-07-25  0:43 UTC (permalink / raw)
  To: meta

We were doing unneccessary 40-byte hex comparisons for SHA-1s
in our code when 20-byte comparisons would've been sufficient.
3/4 is a typo fix which didn't hit any warnings before,
either...

Eric Wong (4):
  extsearchidx: favor binary comparison in common case
  lei_search: favor binary OID comparisons
  lei_inspect: fix typo
  lei_mail_sync: locations_for API uses oidbin for comparisons

 lib/PublicInbox/ExtSearchIdx.pm | 4 ++--
 lib/PublicInbox/LeiExportKw.pm  | 7 +++----
 lib/PublicInbox/LeiInspect.pm   | 7 ++++---
 lib/PublicInbox/LeiMailSync.pm  | 7 ++++---
 lib/PublicInbox/LeiSearch.pm    | 6 +++---
 t/lei_mail_sync.t               | 4 ++--
 6 files changed, 18 insertions(+), 17 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-07-25  0:43  7% [PATCH 0/4] favor shorter binary OID comparisons Eric Wong
2021-07-25  0:43  6% ` [PATCH 4/4] lei_mail_sync: locations_for API uses oidbin for comparisons Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).