PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / stats / StatsRepository.php

StatsRepository.php in 404 Solution 4.3.0, at includes/stats/StatsRepository.php

147 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 require_once __DIR__ . '/StatsRepositoryInterface.php';
8 require_once __DIR__ . '/StatsRefreshLock.php';
9 require_once __DIR__ . '/StatsReadRepository.php';
10 require_once __DIR__ . '/StatsDashboardSnapshotCache.php';
11 require_once __DIR__ . '/StatsDigestDataProvider.php';
12 require_once __DIR__ . '/../repositories/ContentKeywordsRepository.php';
13
14 /**
15 * Stable facade for stats aggregation, dashboard snapshots, digest data, and keyword updates.
16 */
17 class ABJ_404_Solution_StatsRepository implements ABJ_404_Solution_StatsRepositoryInterface {
18
19 /** @var int Max age for cached stats-periodic aggregates. */
20 const PERIODIC_STATS_CACHE_TTL_SECONDS = ABJ_404_Solution_StatsReadRepository::PERIODIC_STATS_CACHE_TTL_SECONDS;
21 /** @var int Minimum interval before recalculating expensive stats aggregates. */
22 const PERIODIC_STATS_REFRESH_COOLDOWN_SECONDS = ABJ_404_Solution_StatsReadRepository::PERIODIC_STATS_REFRESH_COOLDOWN_SECONDS;
23 /** @var int Retention for dashboard stats snapshot payload. */
24 const STATS_DASHBOARD_CACHE_TTL_SECONDS = ABJ_404_Solution_StatsDashboardSnapshotCache::STATS_DASHBOARD_CACHE_TTL_SECONDS;
25 /** @var int Minimum time between full stats snapshot recomputes. */
26 const STATS_DASHBOARD_REFRESH_COOLDOWN_SECONDS = ABJ_404_Solution_StatsDashboardSnapshotCache::STATS_DASHBOARD_REFRESH_COOLDOWN_SECONDS;
27 /** @var int Cooldown for distributed refresh locks. */
28 const REFRESH_LOCK_COOLDOWN_SECONDS = ABJ_404_Solution_StatsRefreshLock::REFRESH_LOCK_COOLDOWN_SECONDS;
29
30 /** @var ABJ_404_Solution_StatsReadRepository */
31 private $statsReadRepository;
32
33 /** @var ABJ_404_Solution_StatsDashboardSnapshotCache */
34 private $dashboardSnapshotCache;
35
36 /** @var ABJ_404_Solution_StatsDigestDataProvider */
37 private $digestDataProvider;
38
39 /** @var ABJ_404_Solution_ContentKeywordsRepository */
40 private $contentKeywordsRepository;
41
42 /**
43 * @param ABJ_404_Solution_DatabaseCore $dbCore
44 * @param ABJ_404_Solution_LogsRepositoryInterface $logsRepo
45 * @param ABJ_404_Solution_Functions|null $functions
46 * @param ABJ_404_Solution_Logging|null $logging
47 */
48 public function __construct(
49 ABJ_404_Solution_DatabaseCore $dbCore,
50 ABJ_404_Solution_LogsRepositoryInterface $logsRepo,
51 $functions = null,
52 $logging = null
53 ) {
54 $f = $functions !== null ? $functions : abj_service('functions');
55 $logger = $logging !== null ? $logging : abj_service('logging');
56 $refreshLock = new ABJ_404_Solution_StatsRefreshLock($dbCore);
57
58 $this->statsReadRepository = new ABJ_404_Solution_StatsReadRepository(
59 $dbCore,
60 $logsRepo,
61 $logger,
62 $refreshLock
63 );
64 $this->dashboardSnapshotCache = new ABJ_404_Solution_StatsDashboardSnapshotCache(
65 $this->statsReadRepository,
66 $refreshLock,
67 $logger
68 );
69 $this->digestDataProvider = new ABJ_404_Solution_StatsDigestDataProvider(
70 $dbCore,
71 $logsRepo,
72 $this->statsReadRepository,
73 $logger
74 );
75 $this->contentKeywordsRepository = new ABJ_404_Solution_ContentKeywordsRepository(
76 $dbCore,
77 $f,
78 $logger
79 );
80 }
81
82 /** @inheritDoc */
83 function getStatsCount($query, array $valueParams) {
84 return $this->statsReadRepository->getStatsCount($query, $valueParams);
85 }
86
87 /** @inheritDoc */
88 function getPeriodicStatsSummary($sinceTimestamp, $notFoundDest = '404') {
89 return $this->statsReadRepository->getPeriodicStatsSummary($sinceTimestamp, $notFoundDest);
90 }
91
92 /** @inheritDoc */
93 function getPeriodicStatsSummariesCached($notFoundDest = '404') {
94 return $this->statsReadRepository->getPeriodicStatsSummariesCached($notFoundDest);
95 }
96
97 /** @inheritDoc */
98 function getStatsDashboardSnapshot($allowStale = true) {
99 return $this->dashboardSnapshotCache->getStatsDashboardSnapshot($allowStale);
100 }
101
102 /** @inheritDoc */
103 function refreshStatsDashboardSnapshot($force = false) {
104 return $this->dashboardSnapshotCache->refresh($force);
105 }
106
107 /** @inheritDoc */
108 function getEarliestLogTimestamp() {
109 return $this->statsReadRepository->getEarliestLogTimestamp();
110 }
111
112 /** @inheritDoc */
113 function getConfidenceBandCounts() {
114 return $this->statsReadRepository->getConfidenceBandCounts();
115 }
116
117 /** @inheritDoc */
118 function getTopCapturedForDigest(int $limit): array {
119 return $this->digestDataProvider->getTopCapturedForDigest($limit);
120 }
121
122 /** @inheritDoc */
123 function buildTopCapturedForDigestQuery(int $limit): string {
124 return $this->digestDataProvider->buildTopCapturedForDigestQuery($limit);
125 }
126
127 /** @inheritDoc */
128 function getDigestSummaryStats(): array {
129 return $this->digestDataProvider->getDigestSummaryStats(array($this, 'getStatsCount'));
130 }
131
132 /** @inheritDoc */
133 function getCapturedCountForNotification(): int {
134 return $this->digestDataProvider->getCapturedCountForNotification();
135 }
136
137 /** @inheritDoc */
138 function getPostsNeedingContentKeywords(int $limit = 500): array {
139 return $this->contentKeywordsRepository->getPostsNeedingContentKeywords($limit);
140 }
141
142 /** @inheritDoc */
143 function bulkUpdateContentKeywords(array $idToKeywords): void {
144 $this->contentKeywordsRepository->bulkUpdateContentKeywords($idToKeywords);
145 }
146 }
147