问题
We have a MySQL database with very big number of tables. Unfortunately in 2018 we still use Perl CGI. So loading time of a script is essential.
DBIx::Class
was ruled out by me because it loads about 1.6 sec (so long because it loads Perl definitions for all tables of the DB) what is clearly too much.
How quickly Class::DBI
loads? My main question: Does Perl load information about all available tables (like DBIx::Class
does) when we use Class::DBI
or does it load Perl definitions for only these tables which we actually use?
The following is a DBIx::Class
code which loads 1.6 sec:
#!/usr/bin/perl
package MyApp::Schema;
use lib '.../ORMs/dbix-class';
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces();
1;
(The schema is autogenerated.)
Is there any way to make it faster? How to use it without loading all tables?
回答1:
I really wouldn't recommend Class::DBI. It's been unmaintained for twelve years - and there were good reasons why everyone switched to DBIx::Class.
I would highly recommend working on the problem that leads to you still using CGI. What is preventing you from, for example, using CGI::Emulate::PSGI to trivially convert your CGI code to PSGI apps which you can then deploy in a persistent environment like FastCGI or, better, as a standalone service which you can then access using nginx? Any of these solutions would mean that the DBIx::Class load time is no longer problem.
Obviously, I have no idea what is keeping you tied to CGI. But, in my experience, moving to PSGI solution is often easier than people expect it to be and it will undoubtedly leave you in a better position.
来源:https://stackoverflow.com/questions/51070019/classdbi-does-it-load-all-tables