XF 2.3 Retaining value for all pages of a thread?

Robert9

Well-known member
Let's assume I want to push the count of a user's posts in a thread into the thread's template. Then, I would need to query something like

"SELECT COUNT FROM post WHERE thread_id = AND user_id = ".

But what about pages 2, 3, 4, ...?

Do I want an extra query for each page? Does it make sense to cache this value? If so, where and how? If not, why not?
 
SQL:
SELECT COUNT(*) FROM post WHERE thread_id = ? AND user_id = ?
will give you all the posts made by the user in the thread. There's no pagination concept here since you're doing a COUNT aggregation which will return only a single numeric value.
 
class extension thread,
fetch a value, user/thread/post connected when viewing a thread

a) First view of thread, fetch value, save global
Second view of thread, visiting page 2 of thread, get global, do not fetch value.

b) First, second and every view of thread, fetch value.

a) only one query per thread and user, but save/use global.

b) every view needs a query, but no save/use global.

I dont need any help with syntax of a query, i need to understand what is the better way to fetch a value for a thread.

I could also add a new table and save thread_id, user_id, value or use a global or just query the thing everytime.

I could also add a new field for post to save my value ... but this would be nonsense.

Also i could save some array in a user field, would be also nonsense.
 
Back
Top Bottom