Re(2): [thelist] Xmas (OT)

Chris Zelenak czelenak at nxco.com
Mon, 20 Dec 1999 14:10:22 -0500


So let it be written, so let it be done. :-)

<tip type="databases, speed">
Okay, so you have a long list of arbitrary values ( say, days in the month
), and you want to query a database for each day in the month to see if
there exists an event or meeting for that particular day.   
What this amounts to is 28-31 (if you're using days )different queries to
the database per each page view ; this is, of course, incredibly
inefficient.
What you should try is checking your database before you scan through your
values, and throwing all the values you need into an array ( it works in
our example of days in the month ; other, larger examples, such as a
search engine, would not  ) and close your connection to the database. 
Now all your variables exist in memory, and you have a much higher fetch
time to your values without having to query the database.    If your
language of choice supports it, remember to unset your variables
afterward, to clear the server's memory - though an array might take up
relatively little space, or your language might have an automatic "garbage
collector", there might exist some cases in which the memory freed merits
the time spent adding the extra code.
</tip>

As long as war is continuous, there is no war.
-1984