Jump to content

Which is more efficient for a forum?


LanceT

Recommended Posts

Having little knowledge of efficiency, I was wondering which would be more efficient for counting a user's number of posts for a forum.

 

Option 1

Selecting the total number of posts and topics that the user has made

 

Option 2

Having a user field that keeps track of the number of posts and topics, which is incremented / decreased every time a post is made or deleted.

 

Thanks.

Link to comment
Share on other sites

Creating the proper indexes on the table will yield negligible performance increases in storing the users posts in a field. Not to mention, it's a PITA to have to keep updating the number of posts a user has using method 2.

 

My recommendation is option1.

Link to comment
Share on other sites

I must agree with KeeB, hands down option 1.

 

A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable.

 

Do not try to optimize the database with fancy tricks unless you know it will have a significant performance gain. Let the database do what it is intended to do. Optimize only if needed....

Link to comment
Share on other sites

 

 

A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable.

 

 

Don't really know how to cache queries, does mysql do this automatically or do I have to setup something different?

 

Please help!

Link to comment
Share on other sites

 

 

A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable.

 

 

Don't really know how to cache queries, does mysql do this automatically or do I have to setup something different?

 

Please help!

 

I'm not as familiar with MySQL/PHP, but most databases I encounter, can do stored procedures. In some languages you can also specify to cache the query, for ColdFusion that is with cachedwithin attribute and for Java/JSP you can use PreparedStatements.

 

Perhaps, somebody else can shed some light on how to do this in PHP/MySQL. I'm sure they have an equivalent or do some Google searches.

 

Hope this helps...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.