cfapress wrote on Friday, February 08, 2008:
Oh boy… I’ve gotten pretty deep now.
I’ve found that regardless of which providers are selected from the UI, all provider’s events are loaded from the database when querying. So, when your database grows large and/or you have many providers then the query will take longer to process and also consume more memory.
I’m digging through all this and have been adding little bits to the pnuserapi.php file. I’ll be proposing my changes once I’ve sort this out.
But here’s the quandry I’m working through. I see that somebody added this code:
$pc_username = $_SESSION[‘pc_username’]; // from Michael Brinson 2006-09-19
if (empty($pc_username) || is_array($pc_username)) {
$pc_username = “__PC_ALL__”;
}
…
if(!empty($pc_username) && (strtolower($pc_username) != ‘anonymous’)) {
if($pc_username==’__PC_ALL__’ || $pc_username == -1) {
$ruserid = -1;
} else {
$ruserid = getIDfromUser($pc_username);
}
}
Then later we check ruserid with this:
if(isset($ruserid)) { …
Well, because of the prior code checks for pc_username the value for ruserid will *always* be set to something. So we never reach these lines of code which impact the SQL query:
} elseif(!pnUserLoggedIn()) {
// get all events for anonymous users
$sql .= “AND a.pc_sharing = '” . SHARING_GLOBAL . "’ ";
} else {
// get all events for logged in user plus global events
$sql .= “AND (a.pc_aid = " . $_SESSION[‘authUserID’] . " OR a.pc_sharing = '” . SHARING_GLOBAL . "’) ";
}
Is this getting ugly yet? I’m doing a stream of thought here, so please bear with me.
I’d like to change things around here because nowhere in the SQL query do we check for the chosen Provider IDs. I’ve got it nearly right and will have it working for my situation here. But I needed somebody else to chime in about why we have this $ruserid value clashing horribly with the remainder of the code.
It seems that when the $ruserid idea was added to the code we were limited to queries of the effect:
- get ALL events
- get events matching the logged in user only
Well that’s pretty broad and narrow at the same time.
I propose that the $_SESSION[‘pc_username]’ be taken out of this function. Then it could be passed into the function as a value just like everything else. This way we’re not overriding the function arguments with the overbearing SESSION value.
Sorry if this is pretty thick. As I said, I’m in quite deep right now. This is not a simple question to answer.
Jason