Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Plugin Development - Efficiency?
I’m currently writing a plugin that uses the DB several times and requires the usage of a form. The first version of said program used an individual database call for each and every piece of output (of seven parts in total) and after getting the basic setup running, I then saw how horribly inefficient that was.
What I’ve done since is have one function call the database, extract the info into $GLOBALS[‘field1’]; then parse the form and finally, depending on what is in the form, the individual functions are called.
ie
function main() {
// do database stuff
foreach($results as $album) {
extract(database stuff);
$GLOBALS[‘randomvariable’] = $thisvariable; //about seven of these in total
//get form here
$out .= parse($myform);
} return $out }
function displaythis() {
global $randomvariable;
$out = $randomvariable;
return $out;
}
Question is, is there a better, more efficient way of doing this?
Offline
Re: Plugin Development - Efficiency?
The only way to make it more efficient without knowing the actual queries would be to reduce the number of database calls. If it is possible to retrieve all 7 pieces of information at the same time, then you would save a little bit of overhead from the connection. The real gains will come from properly constructing the sql queries.
Offline
#3 2005-06-24 22:31:40
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Plugin Development - Efficiency?
Ditto.
Offline
#4 2005-06-27 13:04:42
- duffe
- Archived Plugin Author
- Registered: 2005-01-18
- Posts: 39
Re: Plugin Development - Efficiency?
You can also use TXP’s own global variables, but they are not always available. Eg thisarticle. Other than that, I’d say your method is about as efficient as it can get.
Offline
Pages: 1