CodeIgniter Forums
MySQL Forum - Tracking Post Count - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: MySQL Forum - Tracking Post Count (/showthread.php?tid=14721)

MySQL Forum - Tracking Post Count - El Forum - 01-13-2009

Hello, everybody!

I'm creating a simple forum which uses MySQL as the database, and I'm wondering what the best method for tracking users' post count should be. I've never built a forum before, but I would like to get it right the first time round. I'm unsure whether MySQL should count the posts on each page load, or whether I should cache the post count for the user in the database. Caching the post count is more efficient on resources, but it does mean that I need to remember to update the post count whenever a post is deleted or inserted. I'm not sure if this is an acceptable way to build a database.

I'd appreciate everybody's opinion on the subject.


MySQL Forum - Tracking Post Count - El Forum - 01-13-2009

[eluser]Bogdan Tanase[/eluser]
How about a mysql trigger? on update/delete/insert on "posts" table. On each action do a recount for the user who initiated the trigger.

I've never built a forum, so I'm not sure it's the best way...

MySQL Forum - Tracking Post Count - El Forum - 01-13-2009

Thanks for your input. I need to find out about MySQL triggers. Ultimately, I need to try and find a solution that works across all of the databases that CodeIgniter supports with Active Record. Although it's not important at the moment, it's just something I'd like to do if the code forum code ever goes public.

It's just occurred to me that I can, (to some small degree, anyway), emulate a MySQL trigger, by coding the triggers into the model. So when ,for example, $this->forum_model->insert_post() is called, it will call upon $this->forum_model->update_post_count(), or something like that? This method introduces another problem, however. Database functions start being dependant on other functions, (which may be subject to change), and doesn't that go against the whole MVC thing?

Thanks again for your input.