PluginProbe
404 Solution / trunk
404 Solution vtrunk
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 trunk, at includes/stats/StatsRepository.php

148 lines 5.5 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 $dbCore->collationHelper()
75 );
76 $this->contentKeywordsRepository = new ABJ_404_Solution_ContentKeywordsRepository(
77 $dbCore,
78 $f,
79 $logger
80 );
81 }
82
83 /** @inheritDoc */
84 function getStatsCount($query, array $valueParams) {
85 return $this->statsReadRepository->getStatsCount($query, $valueParams);
86 }
87
88 /** @inheritDoc */
89 function getPeriodicStatsSummary($sinceTimestamp, $notFoundDest = '404') {
90 return $this->statsReadRepository->getPeriodicStatsSummary($sinceTimestamp, $notFoundDest);
91 }
92
93 /** @inheritDoc */
94 function getPeriodicStatsSummariesCached($notFoundDest = '404') {
95 return $this->statsReadRepository->getPeriodicStatsSummariesCached($notFoundDest);
96 }
97
98 /** @inheritDoc */
99 function getStatsDashboardSnapshot($allowStale = true) {
100 return $this->dashboardSnapshotCache->getStatsDashboardSnapshot($allowStale);
101 }
102
103 /** @inheritDoc */
104 function refreshStatsDashboardSnapshot($force = false) {
105 return $this->dashboardSnapshotCache->refresh($force);
106 }
107
108 /** @inheritDoc */
109 function getEarliestLogTimestamp() {
110 return $this->statsReadRepository->getEarliestLogTimestamp();
111 }
112
113 /** @inheritDoc */
114 function getConfidenceBandCounts() {
115 return $this->statsReadRepository->getConfidenceBandCounts();
116 }
117
118 /** @inheritDoc */
119 function getTopCapturedForDigest(int $limit): array {
120 return $this->digestDataProvider->getTopCapturedForDigest($limit);
121 }
122
123 /** @inheritDoc */
124 function buildTopCapturedForDigestQuery(int $limit): string {
125 return $this->digestDataProvider->buildTopCapturedForDigestQuery($limit);
126 }
127
128 /** @inheritDoc */
129 function getDigestSummaryStats(): array {
130 return $this->digestDataProvider->getDigestSummaryStats(array($this, 'getStatsCount'));
131 }
132
133 /** @inheritDoc */
134 function getCapturedCountForNotification(): int {
135 return $this->digestDataProvider->getCapturedCountForNotification();
136 }
137
138 /** @inheritDoc */
139 function getPostsNeedingContentKeywords(int $limit = 500): array {
140 return $this->contentKeywordsRepository->getPostsNeedingContentKeywords($limit);
141 }
142
143 /** @inheritDoc */
144 function bulkUpdateContentKeywords(array $idToKeywords): void {
145 $this->contentKeywordsRepository->bulkUpdateContentKeywords($idToKeywords);
146 }
147 }
148