user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: extra check to for redundant messages in HTML view
Date: Sat, 19 Jun 2021 03:22:28 +0000	[thread overview]
Message-ID: <20210619032228.27196-1-e@80x24.org> (raw)

There appears to be some cases of duplicates appearing due to
-extindex.  I haven't nailed down the cause of it, yet, but
this should make things easier for readers using the PSGI
HTML interface in the meantime.

The raw mboxrd remains undeduplicated for now, and the
correct fix/workaround would be some fsck-like mode for
public-inbox-extindex.
---
 lib/PublicInbox/View.pm | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 530c878f..fc0cd77e 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -22,6 +22,7 @@ use PublicInbox::ViewDiff qw(flush_diff);
 use PublicInbox::Eml;
 use Time::Local qw(timegm);
 use PublicInbox::Smsg qw(subject_normalized);
+use PublicInbox::ContentHash qw(content_hash);
 use constant COLS => 72;
 use constant INDENT => '  ';
 use constant TCHILD => '` ';
@@ -35,9 +36,11 @@ sub msg_page_i {
 		$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
 				"../${\mid_href($smsg->{mid})}/" : '';
 		my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
-		multipart_text_as_html($eml, $ctx);
+		if (length($$obuf)) {
+			multipart_text_as_html($eml, $ctx);
+			$$obuf .= '</pre><hr>';
+		}
 		delete $ctx->{obuf};
-		$$obuf .= '</pre><hr>';
 		$$obuf .= html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg};
 		$$obuf;
 	} else { # called by WwwStream::async_next or getline
@@ -53,9 +56,11 @@ sub no_over_html ($) {
 	$ctx->{mhref} = '';
 	PublicInbox::WwwStream::init($ctx);
 	my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
-	multipart_text_as_html($eml, $ctx);
+	if (length($$obuf)) {
+		multipart_text_as_html($eml, $ctx);
+		$$obuf .= '</pre><hr>';
+	}
 	delete $ctx->{obuf};
-	$$obuf .= '</pre><hr>';
 	eval { $$obuf .= html_footer($ctx, $eml) };
 	html_oneshot($ctx, 200, $obuf);
 }
@@ -646,13 +651,16 @@ sub _msg_page_prepare_obuf {
 	my $mids = mids_for_index($eml);
 	my $nr = $ctx->{nr}++;
 	if ($nr) { # unlikely
+		if ($ctx->{chash} eq content_hash($eml)) {
+			warn "W: BUG? @$mids not deduplicated properly\n";
+			return \$rv;
+		}
+		$rv .=
+"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
 		$rv .= '<pre>';
 	} else {
 		$ctx->{first_hdr} = $eml->header_obj;
-		if ($ctx->{smsg}) {
-			$rv .=
-"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
-		}
+		$ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
 		$rv .= "<pre\nid=b>"; # anchor for body start
 	}
 	$ctx->{-upfx} = '../' if $over;

                 reply	other threads:[~2021-06-19  3:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210619032228.27196-1-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.
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).