[ic] HTML in SQL database

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Sat Oct 12 10:14:01 2002


On Sat, Oct 12, 2002 at 08:58:00PM +1000, George Osvald wrote:
> 
> >I will be interested to watch your progress....strongly suggest you
> >use IC 4.9 instead of 4.8, though.
> 
> >You can actually keep just about anything in Interchange in a database
> >instead of a file, but I don't know of anyone who has really tried
> >it. It is not documented.
> 
> >I was thinking about doing a new template -- maybe I will try doing
> >one that stores all of its files in a table.
> 
> 
> My main goal at the moment is to store meta tags and other basic HTML 
> components in the database that I can use for both interchange files (in all 
> catalogs) and flat HTML files. I want to store all the detail product pages 
> as flat files so robots can spider those without a problem. I will also be 
> using HTML code stored in the database in those flat files and whenever I 
> change the data in the database it will affect the whole web site and all the 
> servers (I am working with only two at the moment). For instance in the 
> products table I added column "keywords" and every product or category has 
> specific keywords that I can add in the product pages. The same keywords will 
> be used for the flat pages as well as the IC pages. This will also allow me 
> to update the web site without the need to restart IC, apply changes or even 
> enter IC as a user. Simply changing a single table in my local database and 
> then replicating the table on line will do.

Storing everything in db and building everything dynamically for each
request is one way to go.  Until you start wishing you did not pay the
overhead for each request on items that change only once a year.  So
a mixed cache/static/dynamic system works better.  If you have low
traffic, all dynamic is not bad and it is much easier to maintain.

Consider also that with IC you can load a lot of stuff into the session.
We build our pages static out of the database, then load more
configuration data in the session.
  &load_merchant('my_merchant') unless($Vend::Session->{MERCHANT});
Where load_merchants queries db to stash a merchant hash into
$Vend::Session->{MERCHANT}.
That way you only need start a new session to get the new config.

Something similar in BEGIN{} block to pull slower changing data
into catalog as a whole is nice.  Bottom line, you still have to
have a local flat file telling the catalog where to find the
database (so you can have production and dev db), but it can 
become very small.

Here's a snippet we use to load a handful of long lived hashes
at startup: $T is a hash of templates, $SC is "site config" which
is where most of the catalog.cfg data lives, etc...

BEGIN {
    %DEFAULT=%{$Cache::Data::SC->{default}};
    # We should load at least the locals unless we are doing development
    for(sort keys %{$Cache::Data::SC}) {
        if($_ eq 'default') {
            ::logGlobal("MV::SC BEGIN: skip precompiling DTD for (default).  OK.");
        } else {
            my($dtd,$ref);
            {
                # local $^W=0 unless($opt->{verbose}); # suppress warnings
                $dtd=qq`
my(\$p);
$Cache::Data::DTD->{default}
$Cache::Data::DTD->{$_}
`;
                eval $dtd;
            }
            ::logGlobal("MV::SC BEGIN: eval error ($_,$@)") if($@);
            $DTD->{$_}=$ref;
            ::logGlobal("MV::SC BEGIN: precompiling DTD for ($_).  OK.");
        }
        $RATE->{$_}=$Cache::Data::RATE->{$_};
        $SC->{$_}=$Cache::Data::SC->{$_};
        $T->{$_}=$Cache::Data::T->{$_};
        $XML->{$_}=$Cache::Data::XML->{$_};
        $ZONE->{$_}=$Cache::Data::ZONE->{$_};
    }
}

I don't know if that helps.  See also slashcode for some ideas.




-- 

Christopher F. Miller, Publisher                               cfm@maine.com
MaineStreet Communications, Inc           208 Portland Road, Gray, ME  04039
1.207.657.5078                                         http://www.maine.com/
Content/site management, online commerce, internet integration, Debian linux