about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdx.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-01 10:06:49 +0000
committerEric Wong <e@yhbt.net>2020-06-03 04:04:21 +0000
commit9ab886546cc89f37819e1ef09cb49fd9325b3a41 (patch)
treea5503e8cd73db95f357895997acb39ec57482fb3 /lib/PublicInbox/SearchIdx.pm
parent7d05666ef3a5750c85e481a0c034f1c34f1b70b9 (diff)
downloadpublic-inbox-9ab886546cc89f37819e1ef09cb49fd9325b3a41.tar.gz
smsg: introduce ->populate method
This will eventually replace the __hdr() calling methods and
eradicate {mime} usage from Smsg.  For now, we can eliminate
PublicInbox::Smsg->new since most callers already rely on an
open `bless' to avoid the old {mime} arg.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r--lib/PublicInbox/SearchIdx.pm31
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index b4088933..eb228e6b 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -156,16 +156,14 @@ sub index_text ($$$$) {
         }
 }
 
-sub index_users ($$) {
+sub index_headers ($$) {
         my ($self, $smsg) = @_;
-
-        my $from = $smsg->from;
-        my $to = $smsg->to;
-        my $cc = $smsg->cc;
-
-        index_text($self, $from, 1, 'A'); # A - author
-        index_text($self, $to, 1, 'XTO') if $to ne '';
-        index_text($self, $cc, 1, 'XCC') if $cc ne '';
+        my @x = (from => 'A', # Author
+                subject => 'S', to => 'XTO', cc => 'XCC');
+        while (my ($field, $pfx) = splice(@x, 0, 2)) {
+                my $val = $smsg->{$field};
+                index_text($self, $val, 1, $pfx) if $val ne '';
+        }
 }
 
 sub index_diff_inc ($$$$) {
@@ -285,9 +283,9 @@ sub index_xapian { # msg_iter callback
         if ($part->{is_submsg}) {
                 my $mids = mids_for_index($part);
                 index_ids($self, $doc, $part, $mids);
-                my $smsg = PublicInbox::Smsg->new($part);
-                index_users($self, $smsg);
-                index_text($self, $smsg->subject, 1, 'S') if $smsg->subject;
+                my $smsg = bless {}, 'PublicInbox::Smsg';
+                $smsg->populate($part);
+                index_headers($self, $smsg);
         }
 
         my ($s, undef) = msg_part_text($part, $ct);
@@ -335,10 +333,8 @@ sub index_ids ($$$$) {
 
 sub add_xapian ($$$$) {
         my ($self, $mime, $smsg, $mids) = @_;
-        $smsg->{mime} = $mime; # XXX dangerous
         my $hdr = $mime->header_obj;
         my $doc = $X->{Document}->new;
-        my $subj = $smsg->subject;
         add_val($doc, PublicInbox::Search::TS(), $smsg->{ts});
         my @ds = gmtime($smsg->{ds});
         my $yyyymmdd = strftime('%Y%m%d', @ds);
@@ -348,8 +344,7 @@ sub add_xapian ($$$$) {
 
         my $tg = term_generator($self);
         $tg->set_document($doc);
-        index_text($self, $subj, 1, 'S') if $subj;
-        index_users($self, $smsg);
+        index_headers($self, $smsg);
 
         msg_iter($mime, \&index_xapian, [ $self, $doc ]);
         index_ids($self, $doc, $hdr, $mids);
@@ -392,8 +387,7 @@ sub add_message {
         };
 
         # v1 and tests only:
-        $smsg->{ds} //= msg_datestamp($hdr, $self->{autime});
-        $smsg->{ts} //= msg_timestamp($hdr, $self->{cotime});
+        $smsg->populate($hdr, $self);
 
         eval {
                 # order matters, overview stores every possible piece of
@@ -649,6 +643,7 @@ sub read_log {
                 my $mime = do_cat_mail($git, $blob, \$bytes);
                 $del_cb->($self, $mime);
         }
+        delete @$self{qw(autime cotime)};
         $batch_cb->($nr, $latest, $newest);
 }