PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.2.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.2.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / DataAccess / ArchiveTableDao.php
matomo / app / core / DataAccess Last commit date
LogQueryBuilder 1 year ago Actions.php 2 years ago ArchiveSelector.php 1 year ago ArchiveTableCreator.php 1 year ago ArchiveTableDao.php 1 year ago ArchiveWriter.php 1 year ago ArchivingDbAdapter.php 1 year ago LogAggregator.php 1 year ago LogQueryBuilder.php 1 year ago LogTableTemporary.php 2 years ago Model.php 1 year ago RawLogDao.php 1 year ago TableMetadata.php 1 year ago
ArchiveTableDao.php
105 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\DataAccess;
10
11 use Piwik\Common;
12 use Piwik\Date;
13 use Piwik\Db;
14 use Piwik\Metrics\Formatter;
15 /**
16 * Data Access class for querying numeric & blob archive tables.
17 */
18 class ArchiveTableDao
19 {
20 /**
21 * Analyzes numeric & blob tables for a single table date (ie, `'2015_01'`) and returns
22 * statistics including:
23 *
24 * - number of archives present
25 * - number of invalidated archives
26 * - number of temporary archives
27 * - number of error archives
28 * - number of segment archives
29 * - number of numeric rows
30 * - number of blob rows
31 *
32 * @param string $tableDate ie `'2015_01'`
33 * @return array
34 */
35 public function getArchiveTableAnalysis($tableDate)
36 {
37 $numericQueryEmptyRow = ['count_archives' => '-', 'count_invalidated_archives' => '-', 'count_temporary_archives' => '-', 'count_error_archives' => '-', 'count_segment_archives' => '-', 'count_numeric_rows' => '-'];
38 $tableDate = str_replace("`", "", $tableDate);
39 // for sanity
40 $numericTable = Common::prefixTable("archive_numeric_{$tableDate}");
41 $blobTable = Common::prefixTable("archive_blob_{$tableDate}");
42 // query numeric table
43 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,\n SUM(CASE WHEN name LIKE 'done%' THEN 1 ELSE 0 END) AS count_archives,\n SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_invalidated_archives,\n SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_temporary_archives,\n SUM(CASE WHEN name LIKE 'done%' AND value IN (?, ?) THEN 1 ELSE 0 END) AS count_error_archives,\n SUM(CASE WHEN name LIKE 'done%' AND CHAR_LENGTH(name) > 32 THEN 1 ELSE 0 END) AS count_segment_archives,\n SUM(CASE WHEN name NOT LIKE 'done%' THEN 1 ELSE 0 END) AS count_numeric_rows,\n 0 AS count_blob_rows\n FROM `{$numericTable}`\n GROUP BY idsite, date1, date2, period ORDER BY idsite, period, date1, date2";
44 $rows = Db::fetchAll($sql, array(\Piwik\DataAccess\ArchiveWriter::DONE_INVALIDATED, \Piwik\DataAccess\ArchiveWriter::DONE_OK_TEMPORARY, \Piwik\DataAccess\ArchiveWriter::DONE_ERROR, \Piwik\DataAccess\ArchiveWriter::DONE_ERROR_INVALIDATED));
45 // index result
46 $result = array();
47 foreach ($rows as $row) {
48 $result[$row['label']] = $row;
49 }
50 // query blob table & manually merge results (no FULL OUTER JOIN in mysql)
51 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,\n COUNT(*) AS count_blob_rows,\n SUM(OCTET_LENGTH(value)) AS sum_blob_length\n FROM `{$blobTable}`\n GROUP BY idsite, date1, date2, period ORDER BY idsite, period, date1, date2";
52 foreach (Db::fetchAll($sql) as $blobStatsRow) {
53 $label = $blobStatsRow['label'];
54 if (isset($result[$label])) {
55 $result[$label] = array_merge($result[$label], $blobStatsRow);
56 } else {
57 // ensure rows without numeric entries have the
58 // same internal result array key order
59 $result[$label] = array_merge(['label' => $label], $numericQueryEmptyRow, $blobStatsRow);
60 }
61 }
62 return $result;
63 }
64 /**
65 * Return invalidation queue table data
66 *
67 * @param bool $prettyTime
68 *
69 * @return array
70 * @throws \Exception
71 */
72 public function getInvalidationQueueData(bool $prettyTime = \false) : array
73 {
74 $invalidationsTable = Common::prefixTable("archive_invalidations");
75 $segmentsTable = Common::prefixTable("segment");
76 $sql = "\n SELECT ai.*, s.definition \n FROM `{$invalidationsTable}` ai \n LEFT JOIN `{$segmentsTable}` s ON SUBSTRING(ai.name, 5) = s.hash\n GROUP BY ai.idinvalidation\n ORDER BY ts_invalidated, idinvalidation ASC";
77 $invalidations = Db::fetchAll($sql);
78 $metricsFormatter = new Formatter();
79 $data = [];
80 foreach ($invalidations as $i) {
81 $waiting = (int) Date::now()->getTimestampUTC() - Date::factory($i['ts_invalidated'])->getTimestampUTC();
82 $processing = (int) $i['ts_started'] ? Date::now()->getTimestampUTC() - (int) $i['ts_started'] : '';
83 if ($prettyTime) {
84 $waiting = $metricsFormatter->getPrettyTimeFromSeconds($waiting, \true);
85 if ($processing != '') {
86 $processing = $metricsFormatter->getPrettyTimeFromSeconds($processing, \true);
87 }
88 }
89 $d = [];
90 $d['Invalidation'] = (int) $i['idinvalidation'];
91 $d['Segment'] = $i['definition'];
92 $d['Site'] = (int) $i['idsite'];
93 $d['Period'] = $i['period'] == 1 ? 'Day' : ($i['period'] == 2 ? 'Week' : ($i['period'] == 3 ? 'Month' : ($i['period'] == 4 ? 'Year' : 'Range')));
94 $d['Date'] = $i['period'] == 1 ? $i['date1'] : ($i['period'] == 3 ? substr($i['date1'], 0, 7) : ($i['period'] == 4 ? substr($i['date1'], 0, 4) : $i['date1'] . ' - ' . $i['date2']));
95 $d['TimeQueued'] = $i['ts_invalidated'];
96 $d['Waiting'] = $waiting;
97 $d['Started'] = $i['ts_started'];
98 $d['Processing'] = $processing;
99 $d['Status'] = $i['status'] == 1 ? 'Processing' : 'Queued';
100 $data[] = $d;
101 }
102 return $data;
103 }
104 }
105