In-Portal Issue Tracker

Welcome to the In-Portal Open Source CMS Issue Tracker! This is a central management / tracking tool for all types of tasks / issues / bugs for the In-Portal Project. Before reporting any issues, please make sure to read the Guide into Issue Tracker and How to Properly Test and Report Bugs!

Relationship Graph View Issue ] Dependency Graph ]
related to child of duplicate of

Viewing Issue Simple Details
ID Category Type Reproducibility Date Submitted Last Update
0000378 [In-Portal CMS] Optimization task always 2009-10-12 06:51 2009-11-03 07:19
Reporter alex View Status public  
Assigned To
Priority normal Resolution open  
Status active      
Summary 0000378: Hit countring improvements
Description Tag RegisterHit is used for counting hit count for each category item. There is only one problem with it, because it stores ids of items, that were already visited in this session to session and there fore forces session to be created and additional server resources to be used.

I propose to create Hits table, where all hits (per session) should be stored (for logged in users) and (per ip) for not logged in users. We could clear it's contents once a day (previous day records only, not whole table). Table should be used for checking, that user is already voted or not.
Additional Information Table:

CREATE TABLE `btr_Hits` (
  `HitId` int(11) unsigned NOT NULL auto_increment,
  `BlogId` int(10) unsigned NOT NULL,
  `IPAddress` varchar(15) NOT NULL,
  `IPLong` int(11) NOT NULL,
  `CreatedById` int(11) NOT NULL,
  `CreatedOn` int(11) default NULL,
  `SessionKey` int(10) unsigned NOT NULL,
  PRIMARY KEY (`HitId`),
  KEY `BlogId` (`BlogId`),
  KEY `IPAddress` (`IPAddress`),
  KEY `CreatedById` (`CreatedById`),
  KEY `CreatedOn` (`CreatedOn`),
  KEY `IPLong` (`IPLong`),
  KEY `SessionKey` (`SessionKey`)
);

Tag RegisterHit:

/**
 * Registers hit on detail page
 *
 * @param Array $params
 * @return string
 */
function RegisterHit($params)
{
    $object =& $this->getObject($params);
    /* @var $object kDBItem */

    $user_id = $this->Application->RecallVar('user_id');
    $user_ip = $_SERVER['REMOTE_ADDR'];

    $sql = 'SELECT ' . $this->Application->getUnitOption('hit', 'IDField') . '
            FROM ' . $this->Application->getUnitOption('hit', 'TableName') . '
            WHERE (BlogId = ' . $object->GetID() . ')';

    if ($this->Application->LoggedIn()) {
        // for logged-in - session id + user id
        $sql .= ' AND (CreatedById = ' . $user_id . ') AND (SessionKey = ' . $this->Application->GetSID() . ')';
    }
    else {
        // non-logged in view range is day (from now minus 24 hours)
        $to_date = adodb_mktime();
        $from_date = strtotime('-1 day', $to_date);

        $sql .= ' AND (IPLong = ' . ip2long($user_ip) . ') AND (CreatedOn BETWEEN ' . $from_date . ' AND ' . $to_date . ')';
    }

    $already_viewed = $this->Conn->GetOne($sql);

    if (!$already_viewed) {
        $hit =& $this->Application->recallObject('hit', null, Array ('skip_autoload' => true));
        /* @var $hit kDBItem */

        $hit->SetDBField('BlogId', $object->GetID());
        $hit->Create();
    }

    return '';
}

Database query for deleting old hits:
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'Hits
        WHERE CreatedOn < ' . strtotime('-1 day');
$this->Conn->Query($sql);



Web Development by Intechnic
In-Portal Open Source CMS
In-Portal Open Source CMS
Copyright © 2000 - 2009 MantisBT Group

Powered by Mantis Bugtracker