From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 01/12] smsg: add ->oidbin method
Date: Sat, 16 Oct 2021 01:00:52 +0000 [thread overview]
Message-ID: <20211016010103.30825-2-e@80x24.org> (raw)
In-Reply-To: <20211016010103.30825-1-e@80x24.org>
This makes some of our code less noisy by reducing the
amount of pack('H*', ...) use.
---
lib/PublicInbox/ExtSearch.pm | 2 +-
lib/PublicInbox/ExtSearchIdx.pm | 11 +++++------
lib/PublicInbox/Import.pm | 2 +-
lib/PublicInbox/OverIdx.pm | 3 +--
lib/PublicInbox/Smsg.pm | 6 ++++--
5 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
index 7520e71c3c12..2460d74f5bdb 100644
--- a/lib/PublicInbox/ExtSearch.pm
+++ b/lib/PublicInbox/ExtSearch.pm
@@ -64,7 +64,7 @@ SELECT ibx_id FROM inboxes WHERE eidx_key = ? LIMIT 1
$sth = $dbh->prepare_cached(<<'', undef, 1);
SELECT docid FROM xref3 WHERE oidbin = ? AND xnum = ? AND ibx_id = ? LIMIT 1
- $sth->bind_param(1, pack('H*', $xsmsg->{blob}), SQL_BLOB);
+ $sth->bind_param(1, $xsmsg->oidbin, SQL_BLOB);
# NNTP::cmd_over can set {num} to zero according to RFC 3977 8.3.2
$sth->bind_param(2, $xsmsg->{num} || $xsmsg->{-orig_num});
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index 3d7a6e7d7622..ba7588d53254 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -122,7 +122,7 @@ sub apply_boost ($$) {
$a->[1] <=> $b->[1] # break ties with {xnum}
} @$xr3;
my $new_smsg = $req->{new_smsg};
- return if $xr3->[0]->[2] ne pack('H*', $new_smsg->{blob}); # loser
+ return if $xr3->[0]->[2] ne $new_smsg->oidbin; # loser
# replace the old smsg with the more boosted one
$new_smsg->{num} = $smsg->{num};
@@ -146,7 +146,7 @@ sub _unref_doc ($$$$$;$) {
}
if (defined($oidbin) && defined($xnum) && blessed($ibx) && $ibx->over) {
my $smsg = $ibx->over->get_art($xnum);
- if ($smsg && pack('H*', $smsg->{blob}) eq $oidbin) {
+ if ($smsg && $smsg->oidbin eq $oidbin) {
carp("BUG: (non-fatal) ".$ibx->eidx_key.
" #$xnum $smsg->{blob} still valid");
return;
@@ -270,9 +270,8 @@ sub _blob_missing ($$) { # called when a known $smsg->{blob} is gone
my ($req, $smsg) = @_;
# xnum and ibx are unknown, we only call this when an entry from
# /ei*/over.sqlite3 is bad, not on entries from xap*/over.sqlite3
- my $oidbin = pack('H*', $smsg->{blob});
$req->{self}->git->async_wait_all;
- _unref_doc($req, $smsg, undef, undef, $oidbin);
+ _unref_doc($req, $smsg, undef, undef, $smsg->oidbin);
}
sub ck_existing { # git->cat_async callback
@@ -569,7 +568,7 @@ sub _reindex_finalize ($$$) {
for my $ary (values %$by_chash) {
for my $x (reverse @$ary) {
warn "removing #$docid xref3 $x->{blob}\n";
- my $bin = pack('H*', $x->{blob});
+ my $bin = $x->oidbin;
my $n = _unref_doc($sync, $docid, undef, undef, $bin);
die "BUG: $x->{blob} invalidated #$docid" if $n == 0;
}
@@ -987,7 +986,7 @@ sub dd_smsg { # git->cat_async callback
my $oidx = $self->{oidx};
for my $smsg (@$ary) {
my $gone = $smsg->{num};
- $oidx->merge_xref3($keep->{num}, $gone, $smsg->{blob});
+ $oidx->merge_xref3($keep->{num}, $gone, $smsg->oidbin);
remove_doc($self, $gone);
}
}
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 17adfabd0d25..60ce7b66419b 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -423,7 +423,7 @@ sub add {
$x->dbh;
$x;
};
- return if !$u->set_maybe(pack('H*', $smsg->{blob}), 1);
+ return if !$u->set_maybe($smsg->oidbin, 1);
return if (!$oidx->vivify_xvmd($smsg) &&
$eidx_git->check($smsg->{blob}));
}
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 9fdb26c0d5c2..e7c96e143749 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -620,8 +620,7 @@ UPDATE over SET ddd = ? WHERE num = ?
}
sub merge_xref3 { # used for "-extindex --dedupe"
- my ($self, $keep_docid, $drop_docid, $oidhex) = @_;
- my $oidbin = pack('H*', $oidhex);
+ my ($self, $keep_docid, $drop_docid, $oidbin) = @_;
my $sth = $self->{dbh}->prepare_cached(<<'');
UPDATE OR IGNORE xref3 SET docid = ? WHERE docid = ? AND oidbin = ?
diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm
index a2f54507425f..260ce6bb065e 100644
--- a/lib/PublicInbox/Smsg.pm
+++ b/lib/PublicInbox/Smsg.pm
@@ -9,13 +9,15 @@
# large threads in our WWW UI and the NNTP range responses.
package PublicInbox::Smsg;
use strict;
-use warnings;
-use base qw(Exporter);
+use v5.10.1;
+use parent qw(Exporter);
our @EXPORT_OK = qw(subject_normalized);
use PublicInbox::MID qw(mids references);
use PublicInbox::Address;
use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
+sub oidbin { pack('H*', $_[0]->{blob}) }
+
sub to_doc_data {
my ($self) = @_;
join("\n",
next prev parent reply other threads:[~2021-10-16 1:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-16 1:00 [PATCH 00/16] some yak-shaving and annoyance fixes Eric Wong
2021-10-16 1:00 ` Eric Wong [this message]
2021-10-16 1:00 ` [PATCH 02/12] dir_idle: do not add watches in ->new Eric Wong
2021-10-16 1:00 ` [PATCH 03/12] imapd+nntpd: drop timer-based expiration Eric Wong
2021-10-16 1:00 ` [PATCH 04/12] httpd: move pipeline logic into event_step Eric Wong
2021-10-16 1:00 ` [PATCH 05/12] lei: golf PATH2CFG cleanup Eric Wong
2021-10-16 1:00 ` [PATCH 06/12] lei: always keep cwd fd {3} for ->fchdir Eric Wong
2021-10-16 1:00 ` [PATCH 07/12] lei: more eval guards for die on failure Eric Wong
2021-10-16 1:00 ` [PATCH 08/12] extindex: prune invalid alternate entries on --gc Eric Wong
2021-10-16 1:01 ` [PATCH 09/12] lei_overview: die rather than lei->fail Eric Wong
2021-10-16 1:01 ` [PATCH 10/12] lei_to_mail: quiet down abort messages Eric Wong
2021-10-16 1:01 ` [PATCH 11/12] inbox + search: use 5.10.1 and do some golfing Eric Wong
2021-10-16 1:01 ` [PATCH 12/12] httpd/async: switch to level-triggered epoll Eric Wong
2021-10-16 1:42 ` [PATCH 00/12] some yak-shaving and annoyance fixes Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211016010103.30825-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).