[Koha-devel] Repetitious behavior repeatedly

Andrew Arensburger arensb+koha-devel at ooblick.com
Sat Sep 21 15:58:02 CEST 2002


	Currently, every script and module that requires configuration
values has a snippet of code that reads /etc/koha.conf. This means
that a particular operation might cause a script to read
/etc/koha.conf several times. That can't be good for performance. In
addition, since the snippet of code is nearly identical everywhere,
it's just begging to be put into a separate function.
	To that end, I've written C4::Config module, which reads
/etc/koha.conf (or a file of your choice, or the file pointed to by
the $KOHA_CONF environment variable), and caches the results.
	If people think this is a Good Idea, just let me know where to
send the code.

	Along those same lines, a lot of functions use
	$dbh = C4Connect;
to get a handle to the Koha database. The way C4Connect is
implemented, it creates a new handle each time. So if 'search.pl'
finds ten results, it'll open 14 connections to the database. This
seems wasteful, especially if the web server and database server
aren't the same machine.
	So if C4::Config is well received, I'll also fix C4Connect to
cache the database handle and return the same one each time, if it
can.

	Finally, a number of scripts need to know which branches or
item types exist. But I'll venture that after the initial setup,
neither of these changes more than once every few months. It seems
rather silly to have a script query the database for these values,
when they could be cached locally.
	Hence, it would make sense to save this information in a Perl
module on the web server, so that scripts don't have to query the
database each time. And run a cron job once an hour to regenerate this
module from the information in the database.

	Thoughts? Is this sensible, or am I full of it?

-- 
Andrew Arensburger                      This message *does* represent the
arensb at ooblick.com                      views of ooblick.com
		 Real Programmers use "cat > a.out".




More information about the Koha-devel mailing list