git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J.H." <warthog19@eaglescrag.net>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org, Petr Baudis <pasky@suse.cz>
Subject: Re: [RFC/PATCH] gitweb: Paginate project list
Date: Sat, 10 May 2008 11:28:28 -0700	[thread overview]
Message-ID: <1210444108.11526.139.camel@localhost.localdomain> (raw)
In-Reply-To: <200805101128.59313.jnareb@gmail.com>

$page_size should be moved to a configuration directive, with a possible
default of 100, and there should be an option to turn it off completely
(I.E. kernel.org will likely have it turned off).

It might also be advantageous to generate the entire list and stash that
somewhere, (session on the host side?) and run the pagination out of
that.  Would even allow the user to choose how many items they wish to
see from a drop down maybe?

- John

On Sat, 2008-05-10 at 11:28 +0200, Jakub Narebski wrote:
> Divide projects list and project search results into pages of
> $page_size (currently 100) elements.  Pagination links look
> like shown below:
> 
>   first prev 1 2 3 *4* 5 6 next last
> 
> where *4* denotes current page, is in bold, and isn't a link.
> This would need to be improved for extremely large number of projects
> (repositories), where number of projects divided by page size is very
> large.
> 
> Currently pagination interacts with sorting in a bit strange way.
> When clicking on "sort by" link when on some later page the result is
> not this page sorted, by given page of sorted output.  Perhaps "sort
> by" links should always show first page...
> 
> git_project_list_body() subroutine takes care to fill field (key) we
> sort by for all projects, sort by given ordering, and fill the rest of
> project info only for projects shown.
> 
> NOTE: currently code is not optimal, as it contains a few unnecessary
> array copying, or array fragment copying.
> 
> Signed-off-by: Jakub Narebski <jnareb@gmail.com>
> ---
> This patch depends on earlier "gitweb: Project search", but conceptually
> they are independent; probably fill_project_list_info() improvement to
> do partial filling should be in seaparet commit...
> 
>  gitweb/gitweb.perl |   57 ++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 files changed, 51 insertions(+), 6 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 7e1a9b4..716f7ad 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -3709,10 +3709,10 @@ sub print_sort_th_num {
>  sub git_project_list_body {
>  	my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
>  
> +	$order ||= $default_projects_order;
>  	my ($check_forks) = gitweb_check_feature('forks');
> -	my @projects = fill_project_list_info($projlist, $check_forks);
> +	my @projects = fill_project_list_info($projlist, $check_forks, $order);
>  
> -	$order ||= $default_projects_order;
>  	$from = 0 unless defined $from;
>  	$to = $#projects if (!defined $to || $#projects < $to);
>  
> @@ -3733,9 +3733,10 @@ sub git_project_list_body {
>  		print "<th></th>\n" . # for links
>  		      "</tr>\n";
>  	}
> +	@projects = @projects[$from..$to];
> +	@projects = fill_project_list_info(\@projects, $check_forks);
>  	my $alternate = 1;
> -	for (my $i = $from; $i <= $to; $i++) {
> -		my $pr = $projects[$i];
> +	foreach my $pr (@projects) {
>  		if ($alternate) {
>  			print "<tr class=\"dark\">\n";
>  		} else {
> @@ -4066,6 +4067,46 @@ sub git_project_list {
>  		die_error(undef, "No projects found");
>  	}
>  
> +	my $page_size = 100;
> +	# +1 for incomplete page (not having $page_size items)
> +	my $npages = int(@list / $page_size)+((@list % $page_size) > 0);
> +	# pages are numbered 0..$npages-1
> +	$page = 0 if (!defined $page || $page < 0);
> +	$page = $npages-1 if ($page >= $npages);
> +	my $paging_nav;
> +
> +	if ($npages > 1) {
> +		my @paging = ();
> +		push @paging, $cgi->a({-href => href(-replay=>1, page=>0)},
> +		                      "first");
> +		if ($page > 0) {
> +			push @paging, $cgi->a({-href => href(-replay=>1, page=>$page-1),
> +			                       -accesskey => "p", -title => "Alt-p"},
> +			                      "prev");
> +		} else {
> +			push @paging, "prev";
> +		}
> +		for (my $pg = 0; $pg < $npages; $pg++) {
> +			# links to individual pages are numbered 1..$npages
> +			if ($page == $pg) {
> +				push @paging, '<b>'.($pg+1).'</b>';
> +			} else {
> +				push @paging, $cgi->a({-href => href(-replay=>1, page=>$pg)},
> +				                      $pg+1);
> +			}
> +		}
> +		if ($page < $npages-1) {
> +			push @paging, $cgi->a({-href => href(-replay=>1, page=>$page+1),
> +			                       -accesskey => "n", -title => "Alt-n"},
> +			                      "next");
> +		} else {
> +			push @paging, "next";
> +		}
> +		push @paging, $cgi->a({-href => href(-replay=>1, page=>$npages-1)},
> +		                      "last");
> +		$paging_nav = join(' &sdot; ', @paging);
> +	}
> +
>  	git_header_html();
>  	if (-f $home_text) {
>  		print "<div class=\"index_include\">\n";
> @@ -4081,10 +4122,14 @@ sub git_project_list {
>  		if (defined $searchtype) {
>  			filter_project_list(\@list, $searchtype, $search_regexp)
>  				unless ($searchtype eq 'list_all');
> -			git_project_list_body(\@list, $order);
> +			git_project_list_body(\@list, $order,
> +			                      $page*$page_size, ($page+1)*$page_size - 1,
> +			                      $paging_nav);
>  		}
>  	} else {
> -		git_project_list_body(\@list, $order);
> +		git_project_list_body(\@list, $order,
> +		                      $page*$page_size, ($page+1)*$page_size - 1,
> +		                      $paging_nav);
>  	}
>  	git_footer_html();
>  }

  reply	other threads:[~2008-05-10 18:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-01 10:20 [RFC/PATCH] gitweb: Simplify git_project_list_body Jakub Narebski
2008-05-02 10:30 ` [RFC/PATCH] gitweb: Allow project description in project_index file Jakub Narebski
2008-05-02 13:04   ` Miklos Vajna
2008-05-03  9:03     ` Jakub Narebski
2008-05-04  2:03       ` Miklos Vajna
2008-05-09 13:23       ` [RFC/PATCH] gitweb: Project search Jakub Narebski
2008-05-10  9:28         ` [RFC/PATCH] gitweb: Paginate project list Jakub Narebski
2008-05-10 18:28           ` J.H. [this message]
2008-05-10 22:32             ` Jakub Narebski
2008-05-11  5:53               ` J.H.
2008-05-11 23:51                 ` Jakub Narebski
     [not found]                 ` <8c5c35580805102356p7e5532aah319af921f9b19392@mail.gmail.com>
2008-05-12  7:03                   ` Jakub Narebski
2008-05-12 15:43                     ` Lars Hjemli
2008-05-13  6:55                       ` Jakub Narebski
     [not found]                         ` <8c5c35580805130939m1a1ef8e0yd72402f3c79190ea@mail.gmail.com>
2008-05-13 16:46                           ` Lars Hjemli
2008-05-13 17:04                           ` Jakub Narebski
2008-05-13 19:11                             ` Kristian Høgsberg
2008-05-13 19:30                             ` Lars Hjemli
2008-05-13 23:28                               ` Jakub Narebski
2008-05-14  7:59                                 ` Jakub Narebski

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1210444108.11526.139.camel@localhost.localdomain \
    --to=warthog19@eaglescrag.net \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=pasky@suse.cz \
    /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.
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 NNTP newsgroup(s).