{"thread":{"id":"24852","subject":"[PATCH 1/2] gitweb: Make it possible to paginate projects","startedAt":"2010-08-25T00:18:55Z","lastAt":"2010-08-25T00:18:56Z","messageCount":2,"participants":["Lubomir Rintel"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"148914","messageId":"1282695536-32546-1-git-send-email-lkundrak@v3.sk","threadId":"24852","inReplyTo":null,"subject":"[PATCH 1/2] gitweb: Make it possible to paginate projects","fromName":"Lubomir Rintel","fromEmail":"lkundrak@v3.sk","sentAt":"2010-08-25T00:18:55Z","receivedAt":"2010-08-25T00:18:55Z","isPatch":true,"sender":{"key":"lkundrak@v3.sk","avatar":"https://gravatar.com/avatar/0c78b09297e4f43bda3282627ada927e031aabd945d9a02df75ae525a18952a8?d=mp&s=160"},"body":"This adds simple pagination (next and prev links), to project lists,\nanalogous to what is done for commit history lists.\n---\n gitweb/gitweb.perl |   26 ++++++++++++++++++++++++++\n 1 files changed, 26 insertions(+), 0 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex d0687f4..135ca55 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -255,6 +255,9 @@ our %highlight_ext = (\n \tmap { $_ => 'xml' } qw(xhtml html htm),\n );\n \n+# Set this to non-zero to enable project list pagination\n+our $projects_per_page = 0;\n+\n # You define site-wide feature defaults here; override them with\n # $GITWEB_CONFIG as necessary.\n our %feature = (\n@@ -4613,9 +4616,19 @@ sub git_project_list_body {\n \tmy @projects = fill_project_list_info($projlist, $check_forks);\n \n \t$order ||= $default_projects_order;\n+\t$page ||= 0;\n+\tif ($projects_per_page) {\n+\t\t$from = $page * $projects_per_page unless defined $from;\n+\t\t$to = $from + $projects_per_page - 1 unless defined $to;\n+\t}\n \t$from = 0 unless defined $from;\n \t$to = $#projects if (!defined $to || $#projects < $to);\n \n+\tmy $prev_link = $cgi->a({-href => href(-replay=>1, page=>$page-1),\n+\t\t -accesskey => \"p\", -title => \"Alt-p\"}, \"prev\") if ($page > 0);\n+\tmy $next_link = $cgi->a({-href => href(-replay=>1, page=>$page+1),\n+\t\t -accesskey => \"n\", -title => \"Alt-n\"}, \"next\") if ($#$projlist > $to);\n+\n \tmy %order_info = (\n \t\tproject => { key => 'path', type => 'str' },\n \t\tdescr => { key => 'descr_long', type => 'str' },\n@@ -4709,6 +4722,19 @@ sub git_project_list_body {\n \t\tprint \"<td colspan=\\\"5\\\">$extra</td>\\n\" .\n \t\t      \"</tr>\\n\";\n \t}\n+\n+\tif ($prev_link or $next_link) {\n+\t\tprint \"<tr>\\n\";\n+\t\tif ($check_forks) {\n+\t\t\tprint \"<td></td>\\n\";\n+\t\t}\n+\t\tprint \"<td colspan=\\\"5\\\">\";\n+\t\tprint $prev_link if $prev_link;\n+\t\tprint \" &sdot; \" if $prev_link and $next_link;\n+\t\tprint $next_link if $next_link;\n+\t\tprint \"</td>\\n</tr>\\n\";\n+\t}\n+\n \tprint \"</table>\\n\";\n }\n \n-- \n1.7.2.1\n"},{"id":"148915","messageId":"1282695536-32546-2-git-send-email-lkundrak@v3.sk","threadId":"24852","inReplyTo":"1282695536-32546-1-git-send-email-lkundrak@v3.sk","subject":"[PATCH 2/2] gitweb: Optimize paging when sorted by path","fromName":"Lubomir Rintel","fromEmail":"lkundrak@v3.sk","sentAt":"2010-08-25T00:18:56Z","receivedAt":"2010-08-25T00:18:56Z","isPatch":true,"sender":{"key":"lkundrak@v3.sk","avatar":"https://gravatar.com/avatar/0c78b09297e4f43bda3282627ada927e031aabd945d9a02df75ae525a18952a8?d=mp&s=160"},"body":"There's no need to get authors, description and last modification time\nof a project that's not being shown on a current page. We can only tell\nthat in advance if the list is sorted by pathname.\n---\n gitweb/gitweb.perl |   47 ++++++++++++++++++++++++++++++++++-------------\n 1 files changed, 34 insertions(+), 13 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 135ca55..45584f4 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -4608,12 +4608,30 @@ sub format_sort_th {\n \treturn $sort_th;\n }\n \n+sub git_try_to_order {\n+\tmy ($projects, $order) = @_;\n+\n+\tmy %order_info = (\n+\t\tproject => { key => 'path', type => 'str' },\n+\t\tdescr => { key => 'descr_long', type => 'str' },\n+\t\towner => { key => 'owner', type => 'str' },\n+\t\tage => { key => 'age', type => 'num' }\n+\t);\n+\tmy $oi = $order_info{$order};\n+\treturn undef unless exists $projects->[0]->{$oi->{'key'}};\n+\tif ($oi->{'type'} eq 'str') {\n+\t\t@$projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projects;\n+\t} else {\n+\t\t@$projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projects;\n+\t}\n+\treturn 1;\n+}\n+\n sub git_project_list_body {\n \t# actually uses global variable $project\n \tmy ($projlist, $order, $from, $to, $extra, $no_header) = @_;\n \n \tmy $check_forks = gitweb_check_feature('forks');\n-\tmy @projects = fill_project_list_info($projlist, $check_forks);\n \n \t$order ||= $default_projects_order;\n \t$page ||= 0;\n@@ -4622,26 +4640,29 @@ sub git_project_list_body {\n \t\t$to = $from + $projects_per_page - 1 unless defined $to;\n \t}\n \t$from = 0 unless defined $from;\n-\t$to = $#projects if (!defined $to || $#projects < $to);\n+\t$to = $#$projlist if (!defined $to || $#$projlist < $to);\n \n \tmy $prev_link = $cgi->a({-href => href(-replay=>1, page=>$page-1),\n \t\t -accesskey => \"p\", -title => \"Alt-p\"}, \"prev\") if ($page > 0);\n \tmy $next_link = $cgi->a({-href => href(-replay=>1, page=>$page+1),\n \t\t -accesskey => \"n\", -title => \"Alt-n\"}, \"next\") if ($#$projlist > $to);\n \n-\tmy %order_info = (\n-\t\tproject => { key => 'path', type => 'str' },\n-\t\tdescr => { key => 'descr_long', type => 'str' },\n-\t\towner => { key => 'owner', type => 'str' },\n-\t\tage => { key => 'age', type => 'num' }\n-\t);\n-\tmy $oi = $order_info{$order};\n-\tif ($oi->{'type'} eq 'str') {\n-\t\t@projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;\n-\t} else {\n-\t\t@projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;\n+\t# If we're paginating and can order the list now (by pathname), we\n+\t# don't need to do an unnecessary and expensive query of the details\n+\t# of the projects we're not going to display. Attempt the sort and\n+\t# remove the other projects from the list if the sort is successful.\n+\t# Can't be used with ctags, since it needs a complete project list.\n+\tmy $ordered = git_try_to_order($projlist, $order)\n+\t\tunless gitweb_check_feature('ctags');\n+\tif ($ordered) {\n+\t\t@$projlist = @$projlist[$from..$to];\n+\t\t$to -= $from;\n+\t\t$from = 0;\n \t}\n \n+\tmy @projects = fill_project_list_info($projlist, $check_forks);\n+\tgit_try_to_order(\\@projects, $order) unless $ordered;\n+\n \tmy $show_ctags = gitweb_check_feature('ctags');\n \tif ($show_ctags) {\n \t\tmy %ctags;\n-- \n1.7.2.1\n"}]}