|  | Posted by Sandman on 11/23/06 20:17 
In article <4565b82b$0$325$e4fe514c@news.xs4all.nl>,Erwin Moller
 <since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
 wrote:
 
 > First: Prefetching all members into memory for each page where you need one
 > or two members is absolutely a no-go. You must change that of course.
 > Just fetch the information you need WHEN you need it.
 
 Yes, but if I need to fetch information for 100 members on one page
 making 100 individual SQL queries is also a no-go.
 
 > If I understand correctly your main problem lies in the fact you must fetch
 > the online/offline information for each possible user.
 > Correct?
 
 No, there are lots of other information also being fetched. The
 online/offline status is kept in a seperate db and isn't a problem at
 all actually. Nicknames, labels, ages, full name and such things are
 what is needed. All of that is in the member DB
 
 > This is how I solved this problem when I was in a similar situation:
 > (a rough quick overview to show the idea)
 >
 > 1) Create a table like
 > CREATE TABLE tblOnlineUsers(
 >   userid integer REFERENCES tbluser.userid,
 >   lastActive timestamp
 > )
 >
 > 2) Whenever a logged-in user does something, update the timestamp in this
 > table for that userid.
 
 That's exactly what I'm doing.
 
 > 3) When you are on a page that needs to know the status of online users,
 > just load it into a array with a query like:
 > SELECT userid FROM tblOnlineUsers WHERE (
 >  lastActive > XXX
 > )
 >
 > Where XXX is (now - your sessiontimeout).
 >
 > Now you need some logic to delete the userids for stale users.
 
 I do that in my five minute aggregation script (that aggregates lots
 of stuff for the site). There I delete from member.surfers where
 datetime < date_sub(now(), interval 10 minute)
 
 > (Users that didn't log out, but just closed their browser or walked away to
 > get a nice good lunch of three hours)
 > eg
 > When a random number between 0 and 1 is smaller than 0.1 you delete all
 > records older than the sessiontimeout.
 >
 > You also need to make sure the userid in that table is unique.
 >
 > But this solution has the advantage that:
 > - You don't load all users into memory for each scriptinvocation
 > - Your tblOnlineUsers can be searched very quickly.
 
 Yeah, I'm already doing that. I still need some way to get information
 about arbitrary user X whenever I need it. One way would be to just
 print "[[MEMBERINFO:123]]" and then save "123" in an array, fetch
 information about all id's in that array and then preg_replace() them
 all in the output buffer. But that's not very intelligent either,
 since a SQL query with "select x, x, x from member where id in(<list
 of 100's of ids>)" isn't very good.
 
 So, basically, I need a function to get information about user X from
 a member count of tens of thousands while not being time consuming if
 I do it one time on a page or if I do it 100 times on a page.
 
 
 
 
 
 
 
 
 
 --
 Sandman[.net]
  Navigation: [Reply to this message] |