user/dev discussion of public-inbox itself
 help / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 8/9] searchmsg: favor direct hash access over accessor methods
Date: Sat,  7 Jan 2017 01:44:51 +0000
Message-ID: <20170107014452.9657-9-e@80x24.org> (raw)
In-Reply-To: <20170107014452.9657-1-e@80x24.org>

This is faster, smaller, and more straighforward to me with
fewer layers of indirection.
---
 lib/PublicInbox/Inbox.pm     |  3 ++-
 lib/PublicInbox/Search.pm    |  2 +-
 lib/PublicInbox/SearchIdx.pm |  4 ++--
 lib/PublicInbox/SearchMsg.pm | 33 ++-------------------------------
 4 files changed, 7 insertions(+), 35 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index f77944f..aa4e141 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -216,7 +216,8 @@ sub msg_by_smsg ($$;$) {
 
 	# backwards compat to fallback to msg_by_mid
 	# TODO: remove if we bump SCHEMA_VERSION in Search.pm:
-	defined(my $blob = $smsg->blob) or return msg_by_mid($self, $smsg->mid);
+	defined(my $blob = $smsg->{blob}) or
+			return msg_by_mid($self, $smsg->mid);
 
 	my $str = git($self)->cat_file($blob, $ref);
 	$$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index b59430d..86354b5 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -282,7 +282,7 @@ sub lookup_message {
 		# raises on error:
 		my $doc = $self->{xdb}->get_document($doc_id);
 		$smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
-		$smsg->doc_id($doc_id);
+		$smsg->{doc_id} = $doc_id;
 	}
 	$smsg;
 }
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 832d1cb..87ee0d4 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -155,7 +155,7 @@ sub add_message {
 		if ($smsg) {
 			# convert a ghost to a regular message
 			# it will also clobber any existing regular message
-			$doc_id = $smsg->doc_id;
+			$doc_id = $smsg->{doc_id};
 			$old_tid = $smsg->thread_id;
 		}
 		$smsg = PublicInbox::SearchMsg->new($mime);
@@ -289,7 +289,7 @@ sub link_message {
 	my ($self, $smsg, $old_tid) = @_;
 	my $doc = $smsg->{doc};
 	my $mid = $smsg->mid;
-	my $mime = $smsg->mime;
+	my $mime = $smsg->{mime};
 	my $hdr = $mime->header_obj;
 	my $refs = $hdr->header_raw('References');
 	my @refs = $refs ? ($refs =~ /<([^>]+)>/g) : ();
diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index 4522eb6..5bb0077 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -103,7 +103,7 @@ sub from_name {
 
 sub ts {
 	my ($self) = @_;
-	$self->{ts} ||= eval { str2time($self->mime->header('Date')) } || 0;
+	$self->{ts} ||= eval { str2time($self->{mime}->header('Date')) } || 0;
 }
 
 sub to_doc_data {
@@ -146,36 +146,7 @@ sub mid ($;$) {
 	}
 }
 
-sub _extract_mid { mid_clean(mid_mime($_[0]->mime)) }
-
-sub blob {
-	my ($self, $x40) = @_;
-	if (defined $x40) {
-		$self->{blob} = $x40;
-	} else {
-		$self->{blob};
-	}
-}
-
-sub mime {
-	my ($self, $mime) = @_;
-	if (defined $mime) {
-		$self->{mime} = $mime;
-	} else {
-		# TODO load from git
-		$self->{mime};
-	}
-}
-
-sub doc_id {
-	my ($self, $doc_id) = @_;
-	if (defined $doc_id) {
-		$self->{doc_id} = $doc_id;
-	} else {
-		# TODO load from xapian
-		$self->{doc_id};
-	}
-}
+sub _extract_mid { mid_clean(mid_mime($_[0]->{mime})) }
 
 sub thread_id {
 	my ($self) = @_;
-- 
EW


  parent reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-07  1:44 [PATCH 0/9] misc cleanups and trimming Eric Wong
2017-01-07  1:44 ` [PATCH 1/9] qspawn: prepare to support runtime reloading of Limiter Eric Wong
2017-01-07  1:44 ` [PATCH 2/9] config: always use namespaced "publicinboxlimiter" Eric Wong
2017-01-07  1:44 ` [PATCH 3/9] config: remove unused get() method Eric Wong
2017-01-07  1:44 ` [PATCH 4/9] inbox: describe the full key name Eric Wong
2017-01-07  1:44 ` [PATCH 5/9] inbox: eliminate weaken usage entirely Eric Wong
2017-01-07  2:12   ` [PATCH 10/9] inbox: properly register cleanup timer for git processes Eric Wong
2017-01-11 10:21   ` [PATCH 11/9] inbox: reinstate periodic cleanup of Xapian and SQLite objects Eric Wong
2017-01-07  1:44 ` [PATCH 6/9] config: allow per-inbox nntpserver Eric Wong
2017-01-07  1:44 ` [PATCH 7/9] remove incorrect comment about strftime + locales Eric Wong
2017-01-07  1:44 ` Eric Wong [this message]
2017-01-07  1:44 ` [PATCH 9/9] search: remove subject_summary Eric Wong

Reply instructions:

You may reply publically 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=20170107014452.9657-9-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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox