Lukas W.
Well-known member
I'm trying to replicate the way view counts for threads are done for my own projects entities. However, I haven't been able to fully figure out, why XF2 actually does, what it does.
There is this snippet in the \XF\Repository\Thread:
But I fail to see through the actual point of having such a table instead of directly updating the thread table. What is the benefit of this approach?
There is this snippet in the \XF\Repository\Thread:
PHP:
public function logThreadView(\XF\Entity\Thread $thread)
{
$this->db()->query("
INSERT INTO xf_thread_view
(thread_id, total)
VALUES
(? , 1)
ON DUPLICATE KEY UPDATE
total = total + 1
", $thread->thread_id);
}
public function batchUpdateThreadViews()
{
$db = $this->db();
$db->query("
UPDATE xf_thread AS t
INNER JOIN xf_thread_view AS tv ON (t.thread_id = tv.thread_id)
SET t.view_count = t.view_count + tv.total
");
$db->emptyTable('xf_thread_view');
}
But I fail to see through the actual point of having such a table instead of directly updating the thread table. What is the benefit of this approach?