[Jaws-commits] r13487 - branches/0.8/html/gadgets/VisitCounter

afz at jaws-project.com afz at jaws-project.com
Sun Aug 19 16:28:27 UTC 2012


Author: afz
Date: 2012-08-19 16:28:27 +0000 (Sun, 19 Aug 2012)
New Revision: 13487

Modified:
   branches/0.8/html/gadgets/VisitCounter/Model.php
Log:
[VisitCounter]: improved a little query performance

Modified: branches/0.8/html/gadgets/VisitCounter/Model.php
===================================================================
--- branches/0.8/html/gadgets/VisitCounter/Model.php	2012-08-19 14:20:49 UTC (rev 13486)
+++ branches/0.8/html/gadgets/VisitCounter/Model.php	2012-08-19 16:28:27 UTC (rev 13487)
@@ -45,36 +45,38 @@
                                                 'Y-m-d H:i:s');
         $params['ip']   = $ip;
         $params['now']  = $GLOBALS['db']->Date();
-        $params['step'] = $inc ? 1 : 0;
 
         $sql = '
             SELECT
-                COUNT(*)
+                [ip], [visit_date]
             FROM [[ipvisitor]]
             WHERE
                 [ip] = {ip} AND [visit_date] >= {date}';
 
-        $visited = $GLOBALS['db']->queryOne($sql, $params);
+        $visited = $GLOBALS['db']->queryRow($sql, $params);
         if (Jaws_Error::IsError($visited)) {
             return new Jaws_Error(_t('VISITCOUNTER_ERROR_CANT_ADD_VISIT', $ip), _t('VISITCOUNTER_NAME'));
         }
 
-        if (isset($visited) && $visited > 0) {
+        if (!empty($visited)) {
+            $params['visits']   = $inc ? 1 : 0;
+            $params['old_date'] = $visited['visit_date'];
             $sql = '
                 UPDATE [[ipvisitor]] SET
                     [visit_date] = {now},
-                    [visits]     = [visits] + {step}
+                    [visits]     = [visits] + {visits}
                 WHERE
-                    [ip] = {ip} AND [visit_date] >= {date}';
+                    [ip] = {ip} AND [visit_date] = {old_date}';
         } else {
+            $params['visits'] = 1;
             $sql = '
                 INSERT INTO [[ipvisitor]]
                     ([ip], [visit_date], [visits])
                 VALUES
-                    ({ip}, {now}, 1)';
+                    ({ip}, {now}, {visits})';
         }
 
-        $result = $GLOBALS['db']->query($sql,  $params);
+        $result = $GLOBALS['db']->query($sql, $params);
         if (Jaws_Error::IsError($result)) {
             return new Jaws_Error(_t('VISITCOUNTER_ERROR_CANT_ADD_VISIT', $ip), _t('VISITCOUNTER_NAME'));
         }



More information about the Jaws-commits mailing list