Gossamer Forum
Quote Reply
Saving time on Rebuild
The Scenario: I had a global to produce the list of all father categories (a drop down) for the search calling MySQL like "WHERE Father=>0". Every time I change something and need to Rebuild All, each and every page have to execute that global what consumes time and resources.

The Solution: I did a Perl script to run in cron daily that creates an external file with the categories and get it inserted by INCLUDE or by JS file.
After first rebuild the time was decreased drastically.

Here is the script:
Code:
#!/usr/bin/perl
# This script will generate the Father categories and Subcats
# for use in navigation/javascript
#================================
use strict;
use lib '/var/www/mysite/cgi-bin/admin';
use Links qw/$DB $IN $CFG/;
Links::init('/var/www/mysite/cgi-bin/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;

# Where to save the files
my $place = "/var/www/mysite/cgi-bin";

drop_father();

sub drop_father {

my $cat_db = $DB->table('Category');
my $sth = $cat_db->select (['ID','Name'], { FatherID => 0 } );
$cat_db->select_options ('ORDER BY Name');
my $output;
while (my $cat = $sth->fetchrow_hashref) {
$output .= qq~<option value="$cat->{ID}">$cat->{Name}</option>\n~;
}
open(OUT, ">$place/father.dat") or die "$!";
print OUT $output;
close(OUT);

print "Done Father ...\n";
exit; # get out from memory
}

This script will produce a file called father.dat that can be called by include which is not memory hungry, only disk access.
Scripts like search, add, modify ... will run a little faster.
If is inserted as a JS, another advantage is that if you add a father category you don't have to rebuild all.
Hope this helps someone else.

Happy coding.

Sara

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Blondies can have brains (sometimes...)
Subject Author Views Date
Post Saving time on Rebuild SaraBem 1789 Apr 2, 2007, 1:14 PM