* [RFC 05/11] thread: common sorting code
2015-08-16 8:37 6% [RFC 0/11] work-in-progress search branch updated Eric Wong
@ 2015-08-16 8:37 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-08-16 8:37 UTC (permalink / raw)
To: meta; +Cc: Eric Wong
We'll be sharing the same threading, so it makes sense to sort
replies using the same code and message headers without repeating
ourselves.
This also standardizes on sorting on X-PI-TS (Unix epoch in seconds)
instead over using X-PI-Date differently in two different places
---
lib/PublicInbox/Feed.pm | 25 +++++--------------------
lib/PublicInbox/Thread.pm | 14 ++++++++++++++
lib/PublicInbox/View.pm | 12 ++----------
3 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index f7c2f32..b532559 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -73,11 +73,13 @@ sub generate_html_index {
'</head><body>' . PRE_WRAP;
# sort child messages in chronological order
- $th->order(sub { mime_sort_children(@_) });
+ $th->order(*PublicInbox::Thread::sort_ts);
# except we sort top-level messages reverse chronologically
my $state = [ time, {}, $first, 0 ];
- for (mime_sort_roots($th)) { dump_msg($_, 0, \$html, $state) }
+ for (PublicInbox::Thread::rsort_ts($th->rootset)) {
+ dump_msg($_, 0, \$html, $state)
+ }
Email::Address->purge_cache;
my $footer = nav_footer($args->{cgi}, $last, $feed_opts, $state);
@@ -299,26 +301,9 @@ sub mime_load_for_sort {
my $t = eval { str2time($mime->header('Date')) };
defined($t) or $t = 0;
- $mime->header_set('X-PI-Date', $t);
+ $mime->header_set('X-PI-TS', $t);
push @$messages, $mime;
1;
}
-# children are chronological
-sub mime_sort_children {
- sort {
- $a->topmost->message->header('X-PI-Date') <=>
- $b->topmost->message->header('X-PI-Date')
- } @_;
-}
-
-# parents are reverse chronological
-sub mime_sort_roots {
- my ($th) = @_;
- sort {
- (eval { $b->message->header('X-PI-Date') } || 0) <=>
- (eval { $a->message->header('X-PI-Date') } || 0)
- } $th->rootset;
-}
-
1;
diff --git a/lib/PublicInbox/Thread.pm b/lib/PublicInbox/Thread.pm
index 7dabf24..58efb8d 100644
--- a/lib/PublicInbox/Thread.pm
+++ b/lib/PublicInbox/Thread.pm
@@ -12,6 +12,20 @@ if ($Mail::Thread::VERSION <= 2.55) {
eval q(sub _container_class { 'PublicInbox::Thread::Container' });
}
+sub sort_ts {
+ sort {
+ (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
+ (eval { $b->topmost->message->header('X-PI-TS') } || 0)
+ } @_;
+}
+
+sub rsort_ts {
+ sort {
+ (eval { $b->topmost->message->header('X-PI-TS') } || 0) <=>
+ (eval { $a->topmost->message->header('X-PI-TS') } || 0)
+ } @_;
+}
+
package PublicInbox::Thread::Container;
use strict;
use warnings;
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index fcc98ab..dcdb310 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -67,7 +67,7 @@ sub index_entry {
$subj = PublicInbox::Hval->new_oneline($subj)->as_html;
my $pfx = (' ' x $level);
- my $ts = $mime->header('X-PI-Date');
+ my $ts = $mime->header('X-PI-TS');
my $fmt = '%Y-%m-%d %H:%M UTC';
$ts = POSIX::strftime($fmt, gmtime($ts));
@@ -391,14 +391,6 @@ sub anchor_for {
'm' . mid_compressed(mid_clean($msgid));
}
-# children are chronological
-sub simple_sort_children {
- sort {
- (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=>
- (eval { $b->topmost->message->header('X-PI-TS') } || 0)
- } @_;
-}
-
sub simple_dump {
my ($dst, $root, $node, $level) = @_;
$$dst .= ' ' x $level;
@@ -441,7 +433,7 @@ sub thread_replies {
$root->header_set('X-PI-TS', '0');
my $th = PublicInbox::Thread->new($root, @msgs);
$th->thread;
- $th->order(sub { simple_sort_children(@_) });
+ $th->order(*PublicInbox::Thread::sort_ts);
$root = [ $root->header('Message-ID'),
clean_subj($root->header('Subject')) ];
simple_dump($dst, $root, $_, 0) for $th->rootset;
--
EW
^ permalink raw reply related [relevance 7%]
* [RFC 0/11] work-in-progress search branch updated
@ 2015-08-16 8:37 6% Eric Wong
2015-08-16 8:37 7% ` [RFC 05/11] thread: common sorting code Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2015-08-16 8:37 UTC (permalink / raw)
To: meta
The following changes since commit 2981d6929f400630e575bcc8fc1851bc531e73e9:
view: consistent ordering of Cc: addresses (2015-08-12 22:41:42 +0000)
are available in the git repository at:
git://80x24.org/public-inbox search
for you to fetch changes up to eb5f82b20944d780ac3b2ff9a926c023da9468fd:
implement /s/$SUBJECT_PATH.html lookups (2015-08-16 08:19:53 +0000)
----------------------------------------------------------------
Eric Wong (11):
initial search backend implementation
search: implement index_sync to fixup indexer
extract redundant Message-ID handling code
search: make search results more OO
view: display replies in per-message view
thread: common sorting code
view: reply threading adjustment
view: hoist out index_walk function
www: /t/$MESSAGE_ID.html for threads
search: remove unnecessary xpfx export
implement /s/$SUBJECT_PATH.html lookups
Makefile.PL | 3 +-
lib/PublicInbox/Feed.pm | 25 +-
lib/PublicInbox/Hval.pm | 13 +-
lib/PublicInbox/MID.pm | 27 +++
lib/PublicInbox/Search.pm | 549 ++++++++++++++++++++++++++++++++++++++++++
lib/PublicInbox/SearchMsg.pm | 204 ++++++++++++++++
lib/PublicInbox/Thread.pm | 14 ++
lib/PublicInbox/View.pm | 389 +++++++++++++++++++++++-------
lib/PublicInbox/WWW.pm | 87 ++++++-
public-inbox-index | 29 +++
public-inbox.cgi | 1 +
t/search.t | 239 ++++++++++++++++++
12 files changed, 1456 insertions(+), 124 deletions(-)
create mode 100644 lib/PublicInbox/MID.pm
create mode 100644 lib/PublicInbox/Search.pm
create mode 100644 lib/PublicInbox/SearchMsg.pm
create mode 100755 public-inbox-index
create mode 100644 t/search.t
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-08-16 8:37 6% [RFC 0/11] work-in-progress search branch updated Eric Wong
2015-08-16 8:37 7% ` [RFC 05/11] thread: common sorting code 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).