[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Tiki Stats - Stats for Trackers are wrong

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68c310a3563a3_2c8ef45450277@gitlab-sidekiq-low-urgency-cpu-bound-v2-685db8b9ff-j6h7p.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
7af5f0bb by Domeshow Emmanuel at 2025-09-11T18:02:33+00:00
[FIX] Tiki Stats - Stats for Trackers are wrong
---
* [FIX] Tiki Stats - Stats for Trackers are wrong

See merge request tikiwiki/tiki!8420

- - - - -


3 changed files:

- lib/stats/statslib.php
- templates/tiki-stats.tpl
- tiki-stats.php


Changes:

=====================================
lib/stats/statslib.php
=====================================
@@ -592,11 +592,28 @@ class StatsLib extends TikiLib
     public function trackerStats()
     {
         $stats = [];
-        $stats["trackers"] = $this->query("show table status WHERE `Name` = 'tiki_trackers'", []);
-        $stats["tracker_fields"] = $this->query("show table status WHERE `Name` = 'tiki_tracker_fields'", []);
-        $stats["tiki_tracker_items"] = $this->query("show table status WHERE `Name` = 'tiki_tracker_items'", []);
-        $stats["tiki_tracker_item_attachments"] = $this->query("show table status WHERE `Name` = 'tiki_tracker_item_attachments'", []);
-        $stats["tiki_tracker_options"] = $this->query("show table status WHERE `Name` = 'tiki_tracker_options'", []);
+        $tables = [
+            'trackers' => 'tiki_trackers',
+            'tracker_fields' => 'tiki_tracker_fields',
+            'tiki_tracker_items' => 'tiki_tracker_items',
+            'tiki_tracker_item_attachments' => 'tiki_tracker_item_attachments',
+            'tiki_tracker_options' => 'tiki_tracker_options',
+        ];
+
+        foreach ($tables as $key => $table) {
+            // Accurate row count
+            $stats[$key]['rowCount'] = (int) $this->getOne("SELECT COUNT(*) FROM `$table`", []);
+
+            // Table size via SHOW TABLE STATUS
+            $stat = $this->query("SHOW TABLE STATUS WHERE `Name` = ?", [$table]);
+            $dataLength = 0;
+
+            if (isset($stat->result[0])) {
+                $dataLength = (int) $stat->result[0]['Data_length'];
+            }
+
+            $stats[$key]['dataLengthMb'] = $dataLength / 1024 / 1024;
+        }
         return $stats;
     }
 }


=====================================
templates/tiki-stats.tpl
=====================================
@@ -396,7 +396,7 @@
                             <td>
                             {$data.dataLengthMb} Mb
                             </td>
-                            <td>
+                            <td style="text-align:right;">
                             {$data.rowCount}
                             </td>
                         </tr>


=====================================
tiki-stats.php
=====================================
@@ -99,18 +99,6 @@ $smarty->assign_by_ref('quiz_stats', $quiz_stats);
 if ($prefs['feature_trackers'] == 'y') {
     // Retrieve trackers statistics and prepare extracted data for display.
     $tracker_stats = $statslib->trackerStats();
-    $tracker_stat_data = [];
-    foreach ($tracker_stats as $key => $stat) {
-        if (isset($stat->result[0])) {
-            $tracker_stat_data = $stat->result[0];
-            $extractedTrackerStatsData[$key] = [
-                'dataLengthMb' => $tracker_stat_data['Data_length'] / 1024 / 1024, // Get data lenght in Mb.
-                'rowCount' => $tracker_stat_data['Rows'] + 1 // Number of records + 1, because it starts with 0 index when counting.
-            ];
-        }
-    }
-
-    $tracker_stats = $extractedTrackerStatsData;
 } else {
     $tracker_stats = false;
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7af5f0bbd38934696b8c2e1c93ebf0b7169577f1

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7af5f0bbd38934696b8c2e1c93ebf0b7169577f1
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.