hits counter was broken

This commit is contained in:
Claude 2013-11-08 11:02:42 +01:00
parent c516cbf37f
commit 79e3d7193a

View File

@ -292,27 +292,29 @@ class Pastes extends CI_Model
}
}
// hits
$hits_data = array(
/*
* Hits
* First check if record already exists. If it does, do not insert.
* INSERT IGNORE INTO does not work for postgres.
*/
$this->db->select('count(paste_id) as count');
$this->db->where('paste_id', $pid);
$this->db->where('ip_address', $this->input->ip_address());
$query = $this->db->get('trending');
$hits_count = $query->result_array();
$hits_count = $hits_count[0]['count'];
if ($hits_count == 0)
{
$this->db->insert('trending', array(
'paste_id' => $pid,
'ip_address' => $this->input->ip_address() ,
'created' => mktime() ,
);
$hits_where = array(
'paste_id' => $pid,
'ip_address' => $this->input->ip_address() ,
);
// First check if record already exists. If it does, do not insert.
// INSERT IGNORE INTO does not work for postgres.
$query = $this->db->get('trending', $hits_where);
if ($query->num_rows == 0)
{
$this->db->insert('trending', $hits_data);
));
}
//update hits counter every minute
if (mktime() > (60 + $data['hits_updated']))
{
$this->calculate_hits($pid, $data['hits']);