Skip to content

Commit

Permalink
Update keywords statistics at catalog time
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjdann committed Aug 20, 2024
1 parent 4ba3a15 commit f78b513
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions application/libraries/Catalog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ private function _process_keywords($project_id, $keywords_tag)
$this->ci->project_keyword_model->insert(array('project_id'=>$project_id));
}
}
// For keywords used in this project, update 'instances' field of 'keywords' table now,
// so correct keyword instances stats can be shown on catalog page even before keywords cron stats job runs.
$this->ci->project_keyword_model->set_keywords_statistics_by_project($project_id);

}

Expand Down
22 changes: 21 additions & 1 deletion application/models/Project_keyword_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@

class Project_keyword_model extends MY_Model {


public function set_keywords_statistics_by_project($project_id)
{
$sql = '
UPDATE keywords k
JOIN
(SELECT pk.keyword_id as keyword_id, COUNT(pk.project_id) AS count
FROM project_keywords pk
GROUP BY 1
) as sub
ON k.id = sub.keyword_id
SET k.count = sub.count
WHERE k.id IN
(SELECT keyword_id
FROM project_keywords
WHERE project_id = ?)';


$query = $this->db->query($sql, array($project_id));
}


}

/* End of file project_keyword.php */
Expand Down

0 comments on commit f78b513

Please sign in to comment.