mybb/mybb — pull request #11 by frostschutz (2013-01-26 03:22:06+00:00)
Title: Optimize update_thread_counters() / update_thread_data()

- merge both functions into one, but retain backward compatibility
- save one or two DB queries
- recount replies counter in replies +1 case

2nd attempt after I botched the first one here: https://github.com/mybb/mybb/pull/8

This is a compromise (or a hack, depends on your point of view). For the replies counter query it uses such a condition:

else if($counter == 'replies' && $changes['replies'] === "+1")

That's whay it's only made when someone replies (and any other case where the replies counter is to be incremented by one). All other cases are not affected and updated using relative/absolute counts without extra query as it were.

I've implemented this exception because otherwise it would've made the query even in a real Recount&Rebuild which supplies the function with already determined absolute values.

If the query is unwanted (in general) this else if tree could be removed entirely.

I also got rid of the ternary operator, got rid of an impossible counter<0 case (taken care of by the counter update query), some comment changes. Also did some more testing this time around. Still uses intval() as that's what the original function used.

Regards