* [PATCH 04/13] import: modernize to use Perl 5.10 features
2020-06-01 10:06 5% [PATCH 00/13] smsg: remove tricky {mime} field Eric Wong
@ 2020-06-01 10:06 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-06-01 10:06 UTC (permalink / raw)
To: meta
First, prefer the leaner "parent" module over the heavy "base"
module to establish ISA relationships, since "base" is only
needed for "fields".
The "//" and "//=" operators allow us simplify our code and fix
minor bugs where a value of "0" was disallowed. Yes, we'll
allow "0" as an email address, too, since some twisted BOFH
could theoretically use it as a local user name.
Going forward, we'll also be avoiding "use warnings" and
instead rely on `-w' in the shebang.
---
lib/PublicInbox/Import.pm | 37 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index a901350402c..1a7ed9ce878 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -7,8 +7,8 @@
# requires read-only access.
package PublicInbox::Import;
use strict;
-use warnings;
-use base qw(PublicInbox::Lock);
+use parent qw(PublicInbox::Lock);
+use v5.10.1;
use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::MID qw(mids mid2path);
use PublicInbox::Address;
@@ -24,10 +24,10 @@ sub new {
my ($class, $git, $name, $email, $ibx) = @_;
my $ref = 'refs/heads/master';
if ($ibx) {
- $ref = $ibx->{ref_head} || 'refs/heads/master';
- $name ||= $ibx->{name};
- $email ||= $ibx->{-primary_address};
- $git ||= $ibx->git;
+ $ref = $ibx->{ref_head} // 'refs/heads/master';
+ $name //= $ibx->{name};
+ $email //= $ibx->{-primary_address};
+ $git //= $ibx->git;
}
bless {
git => $git,
@@ -252,7 +252,7 @@ sub remove {
}
my $ident = $self->{ident};
my $now = now_raw();
- $msg ||= 'rm';
+ $msg //= 'rm';
my $len = length($msg) + 1;
print $w "commit $ref\nmark :$commit\n",
"author $ident $now\n",
@@ -277,21 +277,17 @@ sub git_timestamp {
sub extract_cmt_info ($;$) {
my ($mime, $smsg) = @_;
+ # $mime is PublicInbox::Eml, but remains Email::MIME-compatible
my $sender = '';
- my $from = $mime->header('From');
- $from ||= '';
+ my $hdr = $mime->header_obj;
+ my $from = $hdr->header('From') // '';
my ($email) = PublicInbox::Address::emails($from);
my ($name) = PublicInbox::Address::names($from);
if (!defined($name) || !defined($email)) {
- $sender = $mime->header('Sender');
- $sender ||= '';
- if (!defined($name)) {
- ($name) = PublicInbox::Address::names($sender);
- }
- if (!defined($email)) {
- ($email) = PublicInbox::Address::emails($sender);
- }
+ $sender = $hdr->header('Sender') // '';
+ $name //= (PublicInbox::Address::names($sender))[0];
+ $email //= (PublicInbox::Address::emails($sender))[0];
}
if (defined $email) {
# Email::Address::XS may leave quoted '<' in addresses,
@@ -317,11 +313,8 @@ sub extract_cmt_info ($;$) {
warn "no name in From: $from or Sender: $sender\n";
}
- my $hdr = $mime->header_obj;
-
- my $subject = $hdr->header('Subject');
- $subject = '(no subject)' unless defined $subject;
- # Mime decoding can create nulls replace them with spaces to protect git
+ my $subject = $hdr->header('Subject') // '(no subject)';
+ # MIME decoding can create nulls replace them with spaces to protect git
$subject =~ tr/\0/ /;
utf8::encode($subject);
my $at = git_timestamp(my @at = msg_datestamp($hdr));
^ permalink raw reply related [relevance 7%]
* [PATCH 00/13] smsg: remove tricky {mime} field
@ 2020-06-01 10:06 5% Eric Wong
2020-06-01 10:06 7% ` [PATCH 04/13] import: modernize to use Perl 5.10 features Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-06-01 10:06 UTC (permalink / raw)
To: meta
Storing a large PublicInbox::Eml (or in the past, Email::MIME)
object inside a small PublicInbox::Smsg object has historically
been bloat-prone[1] since there may be many small smsgs in
memory at once
Hundreds or thousands of $smsg objects can linger in memory due
to search results and message threading operations. So keep
$eml and $smsg objects independent of each other, for now.
Instead, we'll introduce a $smsg->populate($eml) API to handle
filling in the keys for the importer, indexer, and
non-SQLite-using WWW users.
Furthermore, $smsg->$field dispatch has always been measurably
faster than $smsg->{$field} access in NNTP. Since $smsg->$field
became read-only with the removal of $smsg->{mime}, we can
abandon the $smsg->$field invocations and favor of direct hash
access.
[1] the prime example being what commit 7d02b9e64455831d fixed
("view: stop storing all MIME objects on large threads")
Eric Wong (13):
inbox: introduce smsg_eml method
wwwatomstream: convert callers to use smsg_eml
v2writable: fix non-sensical interpolation in BUG message
import: modernize to use Perl 5.10 features
smsg: introduce ->populate method
smsg: get rid of ->wrap initializer, too
inbox: msg_by_*: remove $(size)ref args
www: remove smsg_mime API and adjust callers
nntp: smsg_range_i: favor ->{$field} lookups when possible
smsg: get rid of remaining {mime} users
smsg: remove ->bytes and ->lines methods
smsg: remove remaining accessor methods
wwwatomstream: drop smsg->{mid} fallback for non-SQLite
Documentation/mknews.perl | 7 +-
lib/PublicInbox/ExtMsg.pm | 2 +-
lib/PublicInbox/Feed.pm | 8 +-
lib/PublicInbox/Import.pm | 69 ++++++++---------
lib/PublicInbox/Inbox.pm | 32 ++++----
lib/PublicInbox/Mbox.pm | 2 +-
lib/PublicInbox/NNTP.pm | 14 +++-
lib/PublicInbox/OverIdx.pm | 3 +-
lib/PublicInbox/SearchIdx.pm | 33 ++++-----
lib/PublicInbox/SearchView.pm | 6 +-
lib/PublicInbox/Smsg.pm | 123 +++++++++++--------------------
lib/PublicInbox/SolverGit.pm | 4 +-
lib/PublicInbox/V2Writable.pm | 11 +--
lib/PublicInbox/View.pm | 63 ++++++++--------
lib/PublicInbox/WwwAtomStream.pm | 8 +-
t/altid.t | 3 +-
t/altid_v2.t | 3 +-
t/import.t | 3 +-
t/search.t | 46 +++++++-----
t/v2mda.t | 4 +-
t/v2writable.t | 5 +-
21 files changed, 207 insertions(+), 242 deletions(-)
^ permalink raw reply [relevance 5%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-06-01 10:06 5% [PATCH 00/13] smsg: remove tricky {mime} field Eric Wong
2020-06-01 10:06 7% ` [PATCH 04/13] import: modernize to use Perl 5.10 features 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).