PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.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 5 years ago Actions.php 5 years ago ArchiveSelector.php 5 years ago ArchiveTableCreator.php 5 years ago ArchiveTableDao.php 5 years ago ArchiveWriter.php 5 years ago ArchivingDbAdapter.php 5 years ago LogAggregator.php 5 years ago LogQueryBuilder.php 5 years ago LogTableTemporary.php 5 years ago Model.php 5 years ago RawLogDao.php 5 years ago TableMetadata.php 5 years ago
ArchiveTableDao.php
89 lines
1 <?php
2 /**
3 * Matomo - 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\Db;
13
14 /**
15 * Data Access class for querying numeric & blob archive tables.
16 */
17 class ArchiveTableDao
18 {
19 /**
20 * Analyzes numeric & blob tables for a single table date (ie, `'2015_01'`) and returns
21 * statistics including:
22 *
23 * - number of archives present
24 * - number of invalidated archives
25 * - number of temporary archives
26 * - number of error archives
27 * - number of segment archives
28 * - number of numeric rows
29 * - number of blob rows
30 *
31 * @param string $tableDate ie `'2015_01'`
32 * @return array
33 */
34 public function getArchiveTableAnalysis($tableDate)
35 {
36 $numericQueryEmptyRow = array(
37 'count_archives' => '-',
38 'count_invalidated_archives' => '-',
39 'count_temporary_archives' => '-',
40 'count_error_archives' => '-',
41 'count_segment_archives' => '-',
42 'count_numeric_rows' => '-',
43 );
44
45 $tableDate = str_replace("`", "", $tableDate); // for sanity
46
47 $numericTable = Common::prefixTable("archive_numeric_$tableDate");
48 $blobTable = Common::prefixTable("archive_blob_$tableDate");
49
50 // query numeric table
51 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,
52 SUM(CASE WHEN name LIKE 'done%' THEN 1 ELSE 0 END) AS count_archives,
53 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_invalidated_archives,
54 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_temporary_archives,
55 SUM(CASE WHEN name LIKE 'done%' AND value = ? THEN 1 ELSE 0 END) AS count_error_archives,
56 SUM(CASE WHEN name LIKE 'done%' AND CHAR_LENGTH(name) > 32 THEN 1 ELSE 0 END) AS count_segment_archives,
57 SUM(CASE WHEN name NOT LIKE 'done%' THEN 1 ELSE 0 END) AS count_numeric_rows,
58 0 AS count_blob_rows
59 FROM `$numericTable`
60 GROUP BY idsite, date1, date2, period";
61
62 $rows = Db::fetchAll($sql, array(ArchiveWriter::DONE_INVALIDATED, ArchiveWriter::DONE_OK_TEMPORARY,
63 ArchiveWriter::DONE_ERROR));
64
65 // index result
66 $result = array();
67 foreach ($rows as $row) {
68 $result[$row['label']] = $row;
69 }
70
71 // query blob table & manually merge results (no FULL OUTER JOIN in mysql)
72 $sql = "SELECT CONCAT_WS('.', idsite, date1, date2, period) AS label,
73 COUNT(*) AS count_blob_rows,
74 SUM(OCTET_LENGTH(value)) AS sum_blob_length
75 FROM `$blobTable`
76 GROUP BY idsite, date1, date1, period";
77
78 foreach (Db::fetchAll($sql) as $blobStatsRow) {
79 $label = $blobStatsRow['label'];
80 if (isset($result[$label])) {
81 $result[$label] = array_merge($result[$label], $blobStatsRow);
82 } else {
83 $result[$label] = $blobStatsRow + $numericQueryEmptyRow;
84 }
85 }
86
87 return $result;
88 }
89 }