user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/9] search pushed and deployed to master
@ 2015-08-17  3:38  7% Eric Wong
  2015-08-17  3:38  5% ` [PATCH 4/9] www: simplify parameter passing to feed Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2015-08-17  3:38 UTC (permalink / raw)
  To: meta

This should appear shortly in: http://public-inbox.org/meta/

Eric Wong (9):
      feed: remove unnecesary time paramenter in index state
      favor /t/ to /s/, since subjects may change mid-thread
      WWW: eliminate "top" parameter for feeds
      www: simplify parameter passing to feed
      terminology: replies => followups
      search: use raw headers without MIME decoding
      feed: disable the generator statement
      drop bodies and messages ASAP after processing
      search: apply mid_compression to subject paths, too

^ permalink raw reply	[relevance 7%]

* [PATCH 4/9] www: simplify parameter passing to feed
  2015-08-17  3:38  7% [PATCH 0/9] search pushed and deployed to master Eric Wong
@ 2015-08-17  3:38  5% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-08-17  3:38 UTC (permalink / raw)
  To: meta

No need to create a new hash when we can reuse the existing one
more.
---
 lib/PublicInbox/Feed.pm | 44 ++++++++++++++++++++++----------------------
 lib/PublicInbox/WWW.pm  | 29 +++++++++++------------------
 2 files changed, 33 insertions(+), 40 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 5a41bea..0e0b0f6 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -17,12 +17,12 @@ use constant {
 
 # main function
 sub generate {
-	my ($class, $args) = @_;
+	my ($class, $ctx) = @_;
 	require XML::Atom::SimpleFeed;
 	require POSIX;
-	my $max = $args->{max} || MAX_PER_PAGE;
+	my $max = $ctx->{max} || MAX_PER_PAGE;
 
-	my $feed_opts = get_feedopts($args);
+	my $feed_opts = get_feedopts($ctx);
 	my $addr = $feed_opts->{address};
 	$addr = $addr->[0] if ref($addr);
 	my $feed = XML::Atom::SimpleFeed->new(
@@ -37,8 +37,8 @@ sub generate {
 		updated => POSIX::strftime(DATEFMT, gmtime),
 	);
 
-	my $git = PublicInbox::GitCatFile->new($args->{git_dir});
-	each_recent_blob($args, sub {
+	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+	each_recent_blob($ctx, sub {
 		my ($add) = @_;
 		add_to_feed($feed_opts, $feed, $add, $git);
 	});
@@ -48,19 +48,19 @@ sub generate {
 }
 
 sub generate_html_index {
-	my ($class, $args) = @_;
+	my ($class, $ctx) = @_;
 	require PublicInbox::Thread;
 
-	my $max = $args->{max} || MAX_PER_PAGE;
-	my $feed_opts = get_feedopts($args);
+	my $max = $ctx->{max} || MAX_PER_PAGE;
+	my $feed_opts = get_feedopts($ctx);
 
 	my $title = $feed_opts->{description} || '';
 	$title = PublicInbox::Hval->new_oneline($title)->as_html;
 
 	my @messages;
-	my $git_dir = $args->{git_dir};
+	my $git_dir = $ctx->{git_dir};
 	my $git = PublicInbox::GitCatFile->new($git_dir);
-	my ($first, $last) = each_recent_blob($args, sub {
+	my ($first, $last) = each_recent_blob($ctx, sub {
 		mime_load_for_sort($git, $_[0], \@messages);
 	});
 	$git = undef; # destroy pipes.
@@ -76,15 +76,15 @@ sub generate_html_index {
 	$th->order(*PublicInbox::Thread::sort_ts);
 
 	# except we sort top-level messages reverse chronologically
-	my $state = [ $args->{srch}, {}, $first, 0 ];
+	my $state = [ $ctx->{srch}, {}, $first, 0 ];
 	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);
+	my $footer = nav_footer($ctx->{cgi}, $last, $feed_opts, $state);
 	if ($footer) {
-		my $list_footer = $args->{footer};
+		my $list_footer = $ctx->{footer};
 		$footer .= "\n" . $list_footer if $list_footer;
 		$footer = "<hr />" . PRE_WRAP . "$footer</pre>";
 	}
@@ -115,13 +115,13 @@ sub nav_footer {
 }
 
 sub each_recent_blob {
-	my ($args, $cb) = @_;
-	my $max = $args->{max} || MAX_PER_PAGE;
+	my ($ctx, $cb) = @_;
+	my $max = $ctx->{max} || MAX_PER_PAGE;
 	my $hex = '[a-f0-9]';
 	my $addmsg = qr!^:000000 100644 \S+ \S+ A\t(${hex}{2}/${hex}{38})$!;
 	my $delmsg = qr!^:100644 000000 \S+ \S+ D\t(${hex}{2}/${hex}{38})$!;
 	my $refhex = qr/${hex}{4,40}(?:~\d+)?/;
-	my $cgi = $args->{cgi};
+	my $cgi = $ctx->{cgi};
 
 	# revision ranges may be specified
 	my $range = 'HEAD';
@@ -133,7 +133,7 @@ sub each_recent_blob {
 	# get recent messages
 	# we could use git log -z, but, we already know ssoma will not
 	# leave us with filenames with spaces in them..
-	my @cmd = ('git', "--git-dir=$args->{git_dir}",
+	my @cmd = ('git', "--git-dir=$ctx->{git_dir}",
 			qw/log --no-notes --no-color --raw -r
 			   --abbrev=16 --abbrev-commit/);
 	push @cmd, $range;
@@ -178,12 +178,12 @@ sub each_recent_blob {
 
 # private functions below
 sub get_feedopts {
-	my ($args) = @_;
-	my $pi_config = $args->{pi_config};
-	my $listname = $args->{listname};
-	my $cgi = $args->{cgi};
+	my ($ctx) = @_;
+	my $pi_config = $ctx->{pi_config};
+	my $listname = $ctx->{listname};
+	my $cgi = $ctx->{cgi};
 	my %rv;
-	if (open my $fh, '<', "$args->{git_dir}/description") {
+	if (open my $fh, '<', "$ctx->{git_dir}/description") {
 		chomp($rv{description} = <$fh>);
 		close $fh;
 	}
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 7cbfa35..be34e1c 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -111,14 +111,10 @@ sub invalid_list_mid {
 sub get_atom {
 	my ($ctx, $cgi) = @_;
 	require PublicInbox::Feed;
+	$ctx->{pi_config} = $pi_config;
+	$ctx->{cgi} = $cgi;
 	[ 200, [ 'Content-Type' => 'application/xml' ],
-	  [ PublicInbox::Feed->generate({
-			git_dir => $ctx->{git_dir},
-			listname => $ctx->{listname},
-			pi_config => $pi_config,
-			cgi => $cgi,
-		}) ]
-	];
+	  [ PublicInbox::Feed->generate($ctx) ] ]
 }
 
 # /$LISTNAME/?r=$GIT_COMMIT                 -> HTML only
@@ -126,16 +122,11 @@ sub get_index {
 	my ($ctx, $cgi) = @_;
 	require PublicInbox::Feed;
 	my $srch = searcher($ctx);
+	$ctx->{pi_config} = $pi_config;
+	$ctx->{cgi} = $cgi;
+	footer($ctx);
 	[ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
-	  [ PublicInbox::Feed->generate_html_index({
-			srch => $srch,
-			git_dir => $ctx->{git_dir},
-			listname => $ctx->{listname},
-			pi_config => $pi_config,
-			cgi => $cgi,
-			footer => footer($ctx),
-		}) ]
-	];
+	  [ PublicInbox::Feed->generate_html_index($ctx) ] ]
 }
 
 # just returns a string ref for the blob in the current ctx
@@ -275,6 +266,7 @@ sub footer {
 	my $footer = try_cat("$git_dir/public-inbox/footer.html");
 	if (defined $footer) {
 		chomp $footer;
+		$ctx->{footer} = $footer;
 		return $footer;
 	}
 
@@ -304,7 +296,8 @@ sub footer {
 
 	$addr = "<a\nhref=\"mailto:$addr\">$addr</a>";
 	$desc =  $desc;
-	join("\n",
+
+	$ctx->{footer} = join("\n",
 		'- ' . $desc,
 		"A <a\nhref=\"" . PI_URL .  '">public-inbox</a>, ' .
 			'anybody may post in plain-text (not HTML):',
@@ -319,7 +312,7 @@ sub searcher {
 	my ($ctx) = @_;
 	eval {
 		require PublicInbox::Search;
-		PublicInbox::Search->new($ctx->{git_dir});
+		$ctx->{srch} = PublicInbox::Search->new($ctx->{git_dir});
 	};
 }
 
-- 
EW


^ permalink raw reply related	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-08-17  3:38  7% [PATCH 0/9] search pushed and deployed to master Eric Wong
2015-08-17  3:38  5% ` [PATCH 4/9] www: simplify parameter passing to feed 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).