Welcome Guest, Not a member yet? Register   Sign In
Forum prototype - Constructive criticism requested.
#41

[eluser]Dam1an[/eluser]
Fuzzy, you might be interested in this thread, someone else just released a CI forum (with source)
#42

[eluser]TheFuzzy0ne[/eluser]
Oooh! Thanks! Big Grin
#43

[eluser]TheFuzzy0ne[/eluser]
OK, I'm back with another fairly straight forward question, seeking opinions.

When a post is added, I want to increment a counter in the topic row which keeps count of the posts.

Should I:

a) Have the add_post() method call increment_post_count()
b) Call both methods from the controller consecutively

a) Has the advantage of keeping code out of the controller, but it removes some of the control.
b) is the reverse of a), but, as this forum is going to be extendible to some extent, so the code is likely to be modified/extended, and I don't want anyone to have to be an expert to make it work.

I'm sure there's no "right" way to go about this, but I was just wondering what the general consensus was. All comments welcome.
#44

[eluser]Dam1an[/eluser]
I would personally go with a for 2 reasons
1) I can't think of a case when you'd want to add a post but not increment the counter
2) It would be better grouped together, and dependant on your database engine, could even be transactionised

Its also possible to increment the post count without having to get the row, increment the value and put it back, but I can't remember off the top of my head, I'll have a look later, as I'm sure I've used it in some code somewhere
#45

[eluser]TheFuzzy0ne[/eluser]
Good thinking. I was thinking along those lines, but I didn't consider whether or not the two actually needed to be separate.

That database query for updating should be simple enough. Something like:

Code:
$id = 1;
$this->db->where('topic_id', $id);
$this->db->update('posts', array('post_count' => 'post_count + 1'));

... or something along those lines.

Thanks a lot.
#46

[eluser]davidbehler[/eluser]
Quote:1) I can’t think of a case when you’d want to add a post but not increment the counter
What about a post that have to be moderated before they are visible to a normal user? I don't know if Fuzzys board is gonna have that feature, but if so you might have to seperate the 2 calls.
#47

[eluser]Dam1an[/eluser]
[quote author="waldmeister" date="1242082154"]
Quote:1) I can’t think of a case when you’d want to add a post but not increment the counter
What about a post that have to be moderated before they are visible to a normal user? I don't know if Fuzzys board is gonna have that feature, but if so you might have to seperate the 2 calls.[/quote]

I guess I trust these eventual users too much to think of scenarios like that
An alternative might be to have an optional second parameter (boolean) to the first function, so most of the time it will auto incrememnt the post count, but not when you explicitly tell it too
This way has the advantage of staying out the way until you choose otherwise
#48

[eluser]TheFuzzy0ne[/eluser]
Yes, this forum will be moderated. Many thanks for pointing that out. That's something I hadn't considered.
#49

[eluser]jedd[/eluser]
Of course, you really shouldn't have number_of_posts in the database (thread/topic row) at all - it breaks your normalisation rules and consequently risks your database's integrity.

By calculating number of posts per topic when you need to - ie.by using a specific count_posts($topic) method in the model - you can pop your pre-moderated message check logic in there too.


Oh, one other small thing with your method names - I found it easier (and I think this was triggered by playing with PHPDOC a while back) to have names like forum_update(), forum_add(), forum_delete() than your current approach (add_forum(), delete_forum(), etc). Mind, I've always felt more comfortable with a big-endian approach, and have annoyed countless numbers of people with my addiction to 8601.
#50

[eluser]Dam1an[/eluser]
@Jedd: Yes storing any sort of count breaks normalisation, which is why you need to make the call based on the situation. A lot of sites intentionally break normalisation for the sake of performance.

Lets say you have 25 threads/page... that would be 25 calls to the count_posts method, as well as getting the title (and other variables) for those 25 posts, if the post count is stored with the post object, then you only have the 1 query getting those 25 objects




Theme © iAndrew 2016 - Forum software by © MyBB