|
Posted by Sandman on 11/23/06 07:13
So, I have this content management system I've developed myself. The
system has a solid community part where members can register and then
participate in forums, write weblogs and a ton of other things.
So, in instances where I list, for example, the latest weblogs. I list
the headline of the weblog, the date and the name of the member who
wrote it.
Now, the name isn't just "Smith", but rather Smith's online status,
his nick and his "label", and can look like this:
<image> Smith M:34 (Newbie)
The image is either a green or red dot depicting his online status.
When I want to display this, I use this function:
print member_name(12);
With 12 being the id number of Smith, and the only information about
the writer of the weblog (i.e. I don't save his nick or label in the
weblog post, and certainly not his online status).
So, when using member_name() I look up the id 12 in a prefetched array
of members, displaying the correct information. In a compact format:
## index.php
require_once("member.php");
print member_name(12);
## member.php
$q=mysql_query("select id, name, label from members");
while ($r=mysql_fetch_assoc($q)){
$GLOBALS["members"][$r["id"]] = $r;
}
function member_name($id){
$m = $GLOBALS["members"][$id];
$online = in_array($id, $GLOBALS["surfers"]) ? "on" : "off";
return icon("online/$online") . " $m[name] $m[label]";
}
##
So, whenever requiring member.php, all members are prefetched and put
into $GLOBALS["members"], which has worked just fine. Then I have
infromation about any given member at my fingertips.
But now I have some sites which are beginning to get a pretty large
number of members, so prefetching them all becomes timeconsuming
(sometimes up to one second, which is unacceptably slow).
I can't fetch information about each single individual at the point of
showin his or hers information since there can be long lists of for
example weblogs and there might be 40-50 member names to be shown,
which would result in 40-50 seperate mysql requests, which would flood
the MySSQL server, I'm afraid.
So, my question is this; what other way can I do this in? Is there a
faster way to read thousands or even tens of thousands of information
points and put them in an array quickly?
Or is there a better way to read information about single members at
runtime?
Aggregation is most certainly an option. Can I write a tab separated
text file and read that one in member.txt - would it be faster? Should
I write one text file per user and read that file when needed?
Anyone got any experience in doing this? How did you solve it?
Thanks in advance. :)
--
Sandman[.net]
Navigation:
[Reply to this message]
|