Can pagestatistics only insert if page_type == blog_entry ?

Permalink
pagestatistics is sure busy table and bulk :)
thats why i want to minimal the insert record by filtering with blog_entry.

pagestatistics only insert record if page type is blog_entry.

i look into pagestatistics(page_statistics.php) class, but there is no insert query there.

i want just put this filter:
if($c->ctHandle == blog_entry){


where should i put the code?

fastcrash
 
codingpenguins replied on at Permalink Best Answer Reply
This is /concrete/models/user.php. so create a new one in models/user.php. This is the recordView function where the insert happens. I just modified it a little, not sure if this is the best "concrete5" way but it will work. Did not test, but checked the query is fine.
function recordView($c) {
   $db = Loader::db();
   $uID = ($this->uID > 0) ? $this->uID : 0;
   $cID = $c->getCollectionID();
   //check what blog types is
   $handleCheck = 'blog_type';//I did this because mine is 'blog_entry', so you could be looking for something different
   $result = $db->query("Select Pages.ctID FROM PageTypes INNER JOIN Pages ON PageTypes.ctID=Pages.ctID WHERE cID=".$cID." AND ctHandle=".$handleCheck);
   if($result->fetchRow()) { //Checks if we get a row, if so it is the right handle
      $v = array($cID, $uID);
      $db->query("insert into PageStatistics (cID, uID, date) values (?, ?, NOW())", $v);
   }
}


Let me know if you have any questions.

P.S. I created a cron to just remove all the jobs past a week old and save in a new table just by counts for pages.
fastcrash replied on at Permalink Reply
fastcrash
thanks penguins!
that's really help me to find the insert query,
so this not related with page_statistic.php and page.php.

i do this then
function recordView($c) {
   if($c->ctHandle == 'blog_entry'){  // only insert if it was content/blog_type
      $db = Loader::db();
      $uID = ($this->uID > 0) ? $this->uID : 0;
      $cID = $c->getCollectionID();
      $v = array($cID, $uID);
      $db->query("insert into PageStatistics (cID, uID, date) values (?, ?, NOW())", $v);
   }
}


this way we can limited the bulk record insert to pagestatistic.
codingpenguins replied on at Permalink Reply
Yeah, page_statistic.php is used for statistics about a page/pages. More like total views, or views on a particular page. On the other hand page.php is used to have information about the page, like edit mode, is it checked out. The reason it is in user (i believe) is because it is needed to see who is visiting the page, this is called in /concrete/dispatcher.php (which is like the brains of concrete).

Hope this gives you more of an idea about what is going on. And thanks for the clean up, taught me something about variables in a collection variable with less db calls.
ScottC replied on at Permalink Reply
ScottC
The best way would be to hook into concrete5 on_start event or something similar, have the site stats off and turn them on if the page_type event is ran, which means that a page type of blog_type was loaded and you care about the view.
fastcrash replied on at Permalink Reply
fastcrash
Thanks scott for advice, so thats is how the mechanism pagestatistic running.
i will learn that on_start event first

#fast-cgi