Nucleus Core

Login!
Register as a new userLost password?

for Project:

This is the tracker for the Core of the Nucleus CMS-project (Nucleus CMS Website)

FS#115 — Redundant database queries on member table

Attached to Project— Nucleus Core
Opened by Wouter Demuynck (karma) - Wednesday, 19 October 2005, 08:45PM
Last edited by Wouter Demuynck (karma) - Wednesday, 19 October 2005, 08:50PM
Improvement
Management   → Performance
Requires testing
Wouter Demuynck
All
High
High
CVS
3.3
Undecided
90%
When viewing a comments page, a query to the database is made for each comment placed there by a site member, whether the data was already loaded earlier or not

Solution:

- Add a getMember($memberid) method in the MANAGER class (similar to getBlog/getItem/...), as suggested by moraes

- instead of calling MEMBER::createByID(..) in COMMENTS.php, call $manager->getMember()
This task depends upon

This task blocks these from closing
Comment by Wouter Demuynck (karma) - Wednesday, 19 October 2005, 08:54PM

Changes are in CVS.

- The MANAGER class has a &getMember method
- The createByID/createByID in the MEMBER class now return a reference instead of a copy as well (&createByID/&createByName)
- All occurrences of "new MEMBER" / "MEMBER::createFrom" used while handling a non-admin request now go through "manager->getMember()". Code only used in the admin area, as well as the login code hasn't changed


Comment by Rodrigo Moraes (moraes) - Sunday, 23 October 2005, 04:14AM

Good! Will test it out. :-D


Comment by Rodrigo Moraes (moraes) - Monday, 07 November 2005, 02:23AM

I've changed my personal verion of NP_Updated, NP_LatestComments and NP_Online. They all use $manager->getMember() now, and are working fine. I've echo'ed the queries before and after the change, and they were quite reduced! :-D


Comment by Rodrigo Moraes (moraes) - Saturday, 12 November 2005, 12:24PM

I've just fixed in CVS one bug caused by assigning $memberinfo by reference in globalfunctions.php. $memberinfo was not passed to SKIN::parse_member() because the code below didn't work:

$memberinfo =& $manager->getMember($memberid);

It seems global variables can't be assigned by reference. And this makes sense: they are global, so they are already *the same variable* everywhere.


Comment by Wouter Demuynck (karma) - Saturday, 12 November 2005, 01:50PM

I remember something like this from years ago. The code and comment below is in globalfunctions.php, with $blog being a global variable:

$b =& $manager->getBlog($blogid);
$blog = $b; // references can't be placed in global variables?

I guess I left in the temporary $b variable to remember the problem in case I came across the code and felt the urge to change = to =&.

I'm not sure about the global objects being the same everywhere. In PHP 4 (!), I would expect the following code to result in three different objects in memory:

global $mem1, $mem2, $manager;
$mem1 = $manager->getMember(1); // object created in cache + copied to $mem1
$mem2 = $manager->getMember(1); // object copied from cache to $mem2

In PHP5, there will only be one object