@matheusbsbs / matheus-bagliano / commits / ca5e949560
Fork 0

gitweb: speed up project listing on large work trees by limiting find depth

Signed-off-by: Luke Lu <git@vicaya.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Luke Lu committed Oct 16, 2007 at 20:45 UTC ca5e9495607c2abb4b665b75d3d96a457fa4c5dd
3 files changed +13
Makefile
+2
@@ -165,6 +165,7 @@ GITWEB_CONFIG = gitweb_config.perl
165 GITWEB_HOME_LINK_STR = projects
166 GITWEB_SITENAME =
167 GITWEB_PROJECTROOT = /pub/git
168 +GITWEB_PROJECT_MAXDEPTH = 2007
169 GITWEB_EXPORT_OK =
170 GITWEB_STRICT_EXPORT =
171 GITWEB_BASE_URL =
@@ -831,6 +832,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
832 -e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
833 -e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
834 -e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
835 + -e 's|"++GITWEB_PROJECT_MAXDEPTH++"|$(GITWEB_PROJECT_MAXDEPTH)|g' \
836 -e 's|++GITWEB_EXPORT_OK++|$(GITWEB_EXPORT_OK)|g' \
837 -e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \
838 -e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \
gitweb/gitweb.perl
+10
@@ -35,6 +35,10 @@ our $GIT = "++GIT_BINDIR++/git";
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
37
38 +# fs traversing limit for getting project list
39 +# the number is relative to the projectroot
40 +our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
41 +
42 # target of the home link on top of all pages
43 our $home_link = $my_uri || "/";
44
@@ -1509,6 +1513,7 @@ sub git_get_projects_list {
1513 # remove the trailing "/"
1514 $dir =~ s!/+$!!;
1515 my $pfxlen = length("$dir");
1516 + my $pfxdepth = ($dir =~ tr!/!!);
1517
1518 File::Find::find({
1519 follow_fast => 1, # follow symbolic links
@@ -1519,6 +1524,11 @@ sub git_get_projects_list {
1524 return if (m!^[/.]$!);
1525 # only directories can be git repositories
1526 return unless (-d $_);
1527 + # don't traverse too deep (Find is super slow on os x)
1528 + if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1529 + $File::Find::prune = 1;
1530 + return;
1531 + }
1532
1533 my $subdir = substr($File::Find::name, $pfxlen + 1);
1534 # we check related file in $projectroot
t/t9500-gitweb-standalone-no-errors.sh
+1
@@ -18,6 +18,7 @@ gitweb_init () {
18 our \$version = "current";
19 our \$GIT = "git";
20 our \$projectroot = "$(pwd)";
21 +our \$project_maxdepth = 8;
22 our \$home_link_str = "projects";
23 our \$site_name = "[localhost]";
24 our \$site_header = "";