From 62b80b61d334361677e26e9ddb966e6bc5f8635d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 1 Jun 2020 10:06:56 +0000 Subject: smsg: remove remaining accessor methods We'll continue to favor simpler data models that can be used directly rather than wasting time and memory with accessor APIs. The ->from, ->to, -cc, ->mid, ->subject, >references methods can all be trivially replaced by hash lookups since all their values are stored in doc_data. Most remaining callers of those methods were test cases, anyways. ->from_name is only used in the PSGI code, so we can just use ->psgi_cull to take care of populating the {from_name} field. --- lib/PublicInbox/ExtMsg.pm | 2 +- lib/PublicInbox/Mbox.pm | 2 +- lib/PublicInbox/NNTP.pm | 2 +- lib/PublicInbox/OverIdx.pm | 2 +- lib/PublicInbox/Smsg.pm | 45 +++++++-------------------------------------- 5 files changed, 11 insertions(+), 42 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm index 1d17c2ce..d7917b34 100644 --- a/lib/PublicInbox/ExtMsg.pm +++ b/lib/PublicInbox/ExtMsg.pm @@ -30,7 +30,7 @@ our @EXT_URL = map { ascii_html($_) } ( sub PARTIAL_MAX () { 100 } sub mids_from_mset { # Search::retry_reopen callback - [ map { PublicInbox::Smsg::from_mitem($_)->mid } $_[0]->items ]; + [ map { PublicInbox::Smsg::from_mitem($_)->{mid} } $_[0]->items ]; } sub search_partial ($$) { diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index 94e61d4d..b46dacfd 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -151,7 +151,7 @@ sub thread_mbox { return [404, [qw(Content-Type text/plain)], []] if !@$msgs; $ctx->{prev} = $msgs->[-1]; $ctx->{over} = $over; # bump refcnt - PublicInbox::MboxGz->response($ctx, \&thread_cb, $msgs->[0]->subject); + PublicInbox::MboxGz->response($ctx, \&thread_cb, $msgs->[0]->{subject}); } sub emit_range { diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index a37910d1..ac13c7df 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -296,7 +296,7 @@ sub newnews_i { my $msgs = $over->query_ts($ts, $$prev); if (scalar @$msgs) { more($self, '<' . - join(">\r\n<", map { $_->mid } @$msgs ). + join(">\r\n<", map { $_->{mid} } @$msgs ). '>'); $$prev = $msgs->[-1]->{num}; } else { diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm index a078f804..c7f45a6c 100644 --- a/lib/PublicInbox/OverIdx.pm +++ b/lib/PublicInbox/OverIdx.pm @@ -257,7 +257,7 @@ sub add_overview { my $hdr = $mime->header_obj; my $mids = mids_for_index($hdr); my $refs = parse_references($smsg, $hdr, $mids); - my $subj = $smsg->subject; + my $subj = $smsg->{subject}; my $xpath; if ($subj ne '') { $xpath = subject_path($subj); diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm index a7ee2e40..e8f9c9a3 100644 --- a/lib/PublicInbox/Smsg.pm +++ b/lib/PublicInbox/Smsg.pm @@ -28,7 +28,7 @@ sub to_doc_data { join("\n", $self->{subject}, $self->{from}, - $self->references, + $self->{references} // '', $self->{to}, $self->{cc}, $self->{blob}, @@ -74,11 +74,15 @@ sub load_expand { sub psgi_cull ($) { my ($self) = @_; - from_name($self); # fill in {from_name} so we can delete {from} + + # ghosts don't have ->{from} + my $from = delete($self->{from}) // ''; + my @n = PublicInbox::Address::names($from); + $self->{from_name} = join(', ', @n); # drop NNTP-only fields which aren't relevant to PSGI results: # saves ~80K on a 200 item search result: - delete @$self{qw(from ts to cc bytes lines)}; + delete @$self{qw(ts to cc bytes lines)}; $self; } @@ -90,11 +94,6 @@ sub from_mitem { psgi_cull(load_expand($self, $mitem->get_document)); } -sub __hdr ($$) { - my ($self, $field) = @_; - $self->{lc($field)}; -} - # for Import and v1 non-SQLite WWW code paths sub populate { my ($self, $hdr, $v2w) = @_; @@ -128,10 +127,6 @@ sub populate { $self->{mid} //= eval { mids($hdr)->[0] } // ''; } -sub subject ($) { __hdr($_[0], 'Subject') } -sub to ($) { __hdr($_[0], 'To') } -sub cc ($) { __hdr($_[0], 'Cc') } - # no strftime, that is locale-dependent and not for RFC822 my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat); my @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); @@ -146,32 +141,6 @@ sub date ($) { } -sub from ($) { - my ($self) = @_; - my $from = __hdr($self, 'From'); - if (defined $from && !defined $self->{from_name}) { - my @n = PublicInbox::Address::names($from); - $self->{from_name} = join(', ', @n); - } - $from; -} - -sub from_name { - my ($self) = @_; - my $from_name = $self->{from_name}; - return $from_name if defined $from_name; - $self->from; - $self->{from_name}; -} - -sub references { - my ($self) = @_; - my $x = $self->{references}; - defined $x ? $x : ''; -} - -sub mid { $_[0]->{mid} } - our $REPLY_RE = qr/^re:\s+/i; sub subject_normalized ($) { -- cgit v1.2.3-24-ge0c7