PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 6 years ago Actions.php 6 years ago ArchiveSelector.php 6 years ago ArchiveTableCreator.php 6 years ago ArchiveTableDao.php 6 years ago ArchiveWriter.php 6 years ago ArchivingDbAdapter.php 6 years ago LogAggregator.php 5 years ago LogQueryBuilder.php 6 years ago LogTableTemporary.php 6 years ago Model.php 6 years ago RawLogDao.php 6 years ago TableMetadata.php 6 years ago
ArchiveTableDao.php
90 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8
9 namespace Piwik\DataAccess;
10
11 use Piwik\Common;
12 use Piwik\Config;
13 use Piwik\Db;
14
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 = array(
38 'count_archives' => '-',
39 'count_invalidated_archives' => '-',
40 'count_temporary_archives' => '-',
41 'count_error_archives' => '-',
42 'count_segment_archives' => '-',
43 'count_numeric_rows' => '-',
44 );
45
46 $tableDate = str_replace("`", "", $tableDate); // for sanity
47
48 $numericTable = Common::prefixTable("archive_numeric_$tableDate");
49 $blobTable = Common::prefixTable("archive_blob_$tableDate");
50
51 // query numeric table
52 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,
53 SUM(CASE WHEN name LIKE 'done%' THEN 1 ELSE 0 END) AS count_archives,
54 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_invalidated_archives,
55 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_temporary_archives,
56 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_error_archives,
57 SUM(CASE WHEN name LIKE 'done%' AND CHAR_LENGTH(name) > 32 THEN 1 ELSE 0 END) AS count_segment_archives,
58 SUM(CASE WHEN name NOT LIKE 'done%' THEN 1 ELSE 0 END) AS count_numeric_rows,
59 0 AS count_blob_rows
60 FROM `$numericTable`
61 GROUP BY idsite, date1, date2, period";
62
63 $rows = Db::fetchAll($sql, array(ArchiveWriter::DONE_INVALIDATED, ArchiveWriter::DONE_OK_TEMPORARY,
64 ArchiveWriter::DONE_ERROR));
65
66 // index result
67 $result = array();
68 foreach ($rows as $row) {
69 $result[$row['label']] = $row;
70 }
71
72 // query blob table & manually merge results (no FULL OUTER JOIN in mysql)
73 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,
74 COUNT(*) AS count_blob_rows,
75 SUM(OCTET_LENGTH(value)) AS sum_blob_length
76 FROM `$blobTable`
77 GROUP BY idsite, date1, date1, period";
78
79 foreach (Db::fetchAll($sql) as $blobStatsRow) {
80 $label = $blobStatsRow['label'];
81 if (isset($result[$label])) {
82 $result[$label] = array_merge($result[$label], $blobStatsRow);
83 } else {
84 $result[$label] = $blobStatsRow + $numericQueryEmptyRow;
85 }
86 }
87
88 return $result;
89 }
90 }