AndrewSimm
Well-known member
Any rule of thumb of when I should update a count in the database vs using cron?
Currently, my addon updates an article_count column on users, which is used to show article count on the member profile and under member statistics.
These are my
Currently, my addon updates an article_count column on users, which is used to show article count on the member profile and under member statistics.
These are my
_postSave()
and _postDelete()
functions in my Article Entity
PHP:
protected function _postSave()
{
$db = $this->db();
$userId = $this->user_id;
$db->query("
UPDATE xf_user
SET article_count = article_count + 1
WHERE user_id = ?", $userId);
}
protected function _postDelete()
{
$db = $this->db();
$userId = $this->user_id;
$db->query("
UPDATE xf_user
SET article_count = article_count - 1
WHERE user_id = ?", $userId);
}