From 32f898c9515f944eef79ecd719bffe5ae63ac0ae Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 21 Aug 2025 00:18:45 +0200 Subject: [PATCH] optimize --- gorillanest.pl.cgi | 12 +++++++----- gorillanest.pl.fcgi | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi index 4447e17..f71f6e1 100755 --- a/gorillanest.pl.cgi +++ b/gorillanest.pl.cgi @@ -70,12 +70,13 @@ sub serve_template { } my %routes = ( - '/' => sub { serve_template("index.tt", @_) }, - '/~([a-zA-Z0-9_.]+)' => sub { serve_template("index_user.tt", @_) }, - '/~([a-zA-Z0-9_.]+)/([a-zA-Z0-9_.]+)' => sub { serve_template("repository.tt", @_) }, + '/' => sub { serve_template("index.tt", @_) }, + '/~([\w+.])' => sub { serve_template("index_user.tt", @_) }, + '/~([\w+.])/([\w+.]+)' => sub { serve_template("repository.tt", @_) }, ); +my %route_regex_cache = map { $_ => qr{^$_$} } keys %routes; -my $public = 'git/public'; +my $public = 'repos/'; my $dbfile = 'gorillanest.sqlite3'; my %data = ( found => 0, @@ -91,9 +92,10 @@ sub master { my $uri = $ENV{'REQUEST_URI'} || '/'; for my $pattern (keys %routes) { - if ($uri =~ m{^$pattern$}) { + if ($uri =~ $route_regex_cache{$pattern}) { my $handler = $routes{$pattern}; $handler->($uri, $1, $2, $3); + return; } } diff --git a/gorillanest.pl.fcgi b/gorillanest.pl.fcgi index f4c0687..d44df66 100755 --- a/gorillanest.pl.fcgi +++ b/gorillanest.pl.fcgi @@ -6,7 +6,7 @@ use warnings; use Syntax::Keyword::Try; use FCGI; -require "gorillanest.pl.cgi"; +BEGIN { require 'gorillanest.pl.cgi'; } our $request = FCGI::Request(); -- 2.39.5