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