On Sat, Nov 23, 2019 at 12:01:34PM +0000, Stuart Henderson wrote:
> Before:
> 
> # spent 125s within DBI::st::execute which was called 33 times, avg 
> 3.80s/call:
> # 33 times (125s+0s) by DBD::_::db::selectcol_arrayref at line 1694 of 
> DBI.pm, avg 3.80s/call
> sub DBI::st::execute; # xsub
> 
> After:
> 
> # spent 806ms within DBI::st::execute which was called 33 times, avg 
> 24.4ms/call:
> # 33 times (806ms+0s) by DBD::_::db::selectcol_arrayref at line 1694 of 
> DBI.pm, avg 24.4ms/call
> sub DBI::st::execute; # xsub
> 
> OK?
> 
> 
> Index: Utils.pm
> ===================================================================
> RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Utils.pm,v
> retrieving revision 1.4
> diff -u -p -r1.4 Utils.pm
> --- Utils.pm  19 Nov 2019 22:43:31 -0000      1.4
> +++ Utils.pm  23 Nov 2019 12:00:14 -0000
> @@ -64,7 +64,7 @@ sub module_in_ports
>       } ) or die "failed to connect to database: $DBI::errstr";
>  
>       my @results = @{ $dbh->selectcol_arrayref(
> -         "SELECT FULLPKGPATH FROM Ports WHERE DISTNAME LIKE ?",
> +         "SELECT FULLPKGPATH FROM PortsQ WHERE DISTNAME LIKE ?",
>           {}, "$module%"
>       ) };

Woah. That code is horrible. It also spends a lot of time 
connecting/disconnecting.

- The database connection should be a singleton
- sqlports should always be opened ReadOnly
- The query should be prepared.

Apart from that, PortsQ will help, but the basic code should be taken out
and shot.

Reply via email to