PHP Web Host - Quality Web Hosting For All PHP Applications $35/month $250/year (Unlimited) - $25/month - 200,000 impressions - Your Ad Could be Here - Click For Details
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
jimmo
Worker
Worker


Joined: Dec 08, 2005
Posts: 107

PostPosted: Wed Aug 16, 2006 9:24 am Reply with quote Back to top

Hi All!

I am in the process of implementing a combination of the standard Nuke groups and the NSN groups. When I update the Nuke points, I want to immediately make sure that the user is the correct NSN group. Rather than querying the database to check if the user in the right group, I simply do an update for that user even if there is no change.

I found a couple of other places where this type of thing is already being done. One is update_points() in mainfile.php. In this case, the update could be avoided by first checking if points=0, in which case no update is necessary.

However, it seems to me that in my case since I have to access the database anyway why not simply do an update and not a query and then update. In any case, I have to do at least the query every time I add points. However, I am saving the time for the second DB access when I actually have to make a change. Granted, the user will have to make dozens if not hundreds of changes to move from one group to another, so an update that is really necessary will not be a common occurrence.

Writing the code would be simpler (which is a happy thing) as I don't have to build in any checks. Also, I do not see any real problems at the moment with doing the update all of the time, but I am curious as to what others think about doing it.

Regards,

jimmo
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Thu Aug 17, 2006 5:44 am Reply with quote Back to top

In this specific case that you mention, the approach sounds reasonable.

Just an "aside": I do not have experience with mySQL from a DBA perspective, but one of the things I would be concerned with if this was Oracle, is if I had archive logging turned on (i.e., all edits are logged for forward recovery purposes). An update in this case, would be very wasteful and unnecessary, and I would opt for the query/check option.
View user's profile Send private message Visit poster's website
jimmo
Worker
Worker


Joined: Dec 08, 2005
Posts: 107

PostPosted: Thu Aug 17, 2006 8:27 am Reply with quote Back to top

I've been googling for an atomic way to check and update, but I haven't found anything. A SELECT selects and an UPDATE updates. Hmmmm....

What I though about was to update using a WHERE that matches the user ID and not the group ID. I know what the group should be and only do an update if the group is different. While that does not prevent the second access, it prevents the update when it is not necessary.

Since there are only a handful of groups, I though about hardcoding the values into my custom include file which is loaded anyway. But the question is whether the extra code is worth any potential speed gains.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9136
Location: Arizona

PostPosted: Fri Aug 18, 2006 6:34 am Reply with quote Back to top

Quote:

What I though about was to update using a WHERE that matches the user ID and not the group ID. I know what the group should be and only do an update if the group is different. While that does not prevent the second access, it prevents the update when it is not necessary.

Sounds reasonable.

Quote:

But the question is whether the extra code is worth any potential speed gains.

Depends upon what you are after. If you see no issues with extra db calls, then add them. If you are seeking out the absolute most efficient way to do it, then it begs the question.

You should be fine with either approach.
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum