From: Luke Lu Date: Wed, 17 Oct 2007 03:45:25 +0000 (-0700) Subject: gitweb: speed up project listing on large work trees by limiting find depth X-Git-Url: https://git.ladys.computer/Gitweb/commitdiff_plain/0640c8c9c9cad25736a74a8d03af442887f0a17ebdb67ffccedc268718913059 gitweb: speed up project listing on large work trees by limiting find depth Signed-off-by: Luke Lu Signed-off-by: Shawn O. Pearce --- diff --git a/gitweb.perl b/gitweb.perl index d8b8dee..77ee403 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -35,6 +35,10 @@ our $GIT = "++GIT_BINDIR++/git"; #our $projectroot = "/pub/scm"; our $projectroot = "++GITWEB_PROJECTROOT++"; +# fs traversing limit for getting project list +# the number is relative to the projectroot +our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++"; + # target of the home link on top of all pages our $home_link = $my_uri || "/"; @@ -1510,6 +1514,7 @@ sub git_get_projects_list { # remove the trailing "/" $dir =~ s!/+$!!; my $pfxlen = length("$dir"); + my $pfxdepth = ($dir =~ tr!/!!); File::Find::find({ follow_fast => 1, # follow symbolic links @@ -1520,6 +1525,11 @@ sub git_get_projects_list { return if (m!^[/.]$!); # only directories can be git repositories return unless (-d $_); + # don't traverse too deep (Find is super slow on os x) + if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) { + $File::Find::prune = 1; + return; + } my $subdir = substr($File::Find::name, $pfxlen + 1); # we check related file in $projectroot