From d1b98371ee22b6e2f038650c6046f8063a928022 Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 21 Aug 2025 00:18:23 +0200 Subject: found (CGI) bottleneck --- gorillanest.pl.cgi | 1 - 1 file changed, 1 deletion(-) mode change 100644 => 100755 gorillanest.pl.cgi (limited to 'gorillanest.pl.cgi') diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi old mode 100644 new mode 100755 index c964c8f..4447e17 --- a/gorillanest.pl.cgi +++ b/gorillanest.pl.cgi @@ -4,7 +4,6 @@ use strict; use warnings; use CGI; -use Switch::Back; use Template; use URI::Escape; use Cwd; -- cgit v1.2.3 From 32f898c9515f944eef79ecd719bffe5ae63ac0ae Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 21 Aug 2025 00:18:45 +0200 Subject: optimize --- gorillanest.pl.cgi | 12 +++++++----- gorillanest.pl.fcgi | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'gorillanest.pl.cgi') 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(); -- cgit v1.2.3 From e770a0baff962e38102b261c6eb5102b1bf1ee4a Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 21 Aug 2025 01:28:15 +0200 Subject: bump --- gorillanest.pl.cgi | 60 +++++++++++++++++++++++++++++++----------------------- repos | 1 + template/index.tt | 6 +++++- 3 files changed, 41 insertions(+), 26 deletions(-) create mode 120000 repos (limited to 'gorillanest.pl.cgi') diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi index f71f6e1..beda12a 100755 --- a/gorillanest.pl.cgi +++ b/gorillanest.pl.cgi @@ -1,5 +1,13 @@ #!/usr/bin/env perl +# XXX +# why are we passing around root like a cheap whore? +# looking into it, i think we should have a global config object using +# https://metacpan.org/pod/Readonly +# +# i modified the routing heavily, this is how people do it; +# pretty clean + use strict; use warnings; @@ -19,6 +27,13 @@ sub info { our $template = Template->new({INCLUDE_PATH => 'template'}); +sub serve_template { + my ($template_name, $data) = @_; + + $template->process($template_name, $data) + or info("Template: " . $template->error()); +} + # significant dirs only sub GN::directories { my $root = $_[0]; @@ -37,51 +52,46 @@ sub GN::directories { # probably should output all repos recursively, currently just outputs list of users sub GN::index { # / - my ($root, $dataref) = @_; - my %data = %$dataref; + my ($root) = @_; + my %data; + my @directories = map { my $i = $_; map { join('/', $i, $_) } @{GN::directories(join('/', $root, $i))} } @{GN::directories($root)}; $data{directories} = \@directories; if ($data{directories}) { $data{found} = 1; } - return \%data; + + serve_template("index.tt", \%data); } sub GN::user { # /$username/ - my ($root, $dataref) = @_; - my %data = %$dataref; + my ($root, $username) = @_; + + my %data; my @directories = @{GN::directories(join('/', $root, $data{username}))}; $data{directories} = \@directories; if ($data{directories}) { $data{found} = 1; } - return \%data; + + serve_template("index_user.tt", \%data); } sub GN::repository { # /$username/$repository - my ($root, $dataref) = @_; - my %data = %$dataref; - $data{found} = 0; - return \%data; -} + my ($root, $username, $repository) = @_; -sub serve_template { - my ($file, @rest) = @_; - my %vars = @rest ? @rest : (); - - $template->process($file, \%vars) - or info("Template: " . $template->error()); + die 'not implemented'; } -my %routes = ( - '/' => 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 = 'repos/'; my $dbfile = 'gorillanest.sqlite3'; my %data = ( found => 0, ); +my %routes = ( + '/' => sub { GN::index($public); }, + '/~([\w.]+)' => sub { GN::user($public, @_) }, + '/~([\w.]+)/([\w.]+)' => sub { GN::repository($public, @_) }, +); +my %route_regex_cache = map { $_ => qr{^$_$} } keys %routes; + sub master { my $cgi = CGI->new; my %header = ( @@ -99,7 +109,7 @@ sub master { } } - serve_template("404.tt"); # XXX missing code + serve_template("404.tt", {}); # XXX missing code } master() if !caller; 1; diff --git a/repos b/repos new file mode 120000 index 0000000..bb952f1 --- /dev/null +++ b/repos @@ -0,0 +1 @@ +dummy_repos \ No newline at end of file diff --git a/template/index.tt b/template/index.tt index 90d67e0..ff72c95 100644 --- a/template/index.tt +++ b/template/index.tt @@ -5,7 +5,11 @@
one million [% access %] xolatile's
[% INCLUDE foot.tt %] -- cgit v1.2.3 From 98e32923a3622d01b9bcccd2551ab73a55b740c4 Mon Sep 17 00:00:00 2001 From: anon Date: Thu, 21 Aug 2025 01:36:43 +0200 Subject: comment --- gorillanest.pl.cgi | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gorillanest.pl.cgi') diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi index beda12a..a807fc4 100755 --- a/gorillanest.pl.cgi +++ b/gorillanest.pl.cgi @@ -7,6 +7,9 @@ # # i modified the routing heavily, this is how people do it; # pretty clean +# you must also realize that not all routes are necessarily templates, +# it could be a redirect for example, so the original solution would +# complicate beyond comprehension use strict; use warnings; -- cgit v1.2.3