20 private const CACHE_KEY =
'messageBundle';
21 private const CACHE_VERSION = 1;
24 protected IDatabase $db;
30 $this->cache = $cache;
33 'key' => self::CACHE_KEY,
34 'version' => self::CACHE_VERSION,
35 'regenerator' =>
function () {
36 return $this->getCacheData();
44 if ( !isset( $this->groups ) ) {
45 $cacheData = $this->cache->getValue();
46 $this->groups = $this->initGroupsFromConf( $cacheData );
52 public function getCacheData(): array {
54 $tables = [
'page',
'revtag' ];
55 $vars = [
'page_id',
'page_namespace',
'page_title',
'rt_revision' =>
'MAX(rt_revision)' ];
56 $conds = [
'page_id=rt_page',
'rt_type' => RevTagStore::MB_VALID_TAG ];
58 'GROUP BY' =>
'page_id,page_namespace,page_title'
60 $res = $this->db->select( $tables, $vars, $conds, __METHOD__, $options );
62 foreach ( $res as $r ) {
63 $title = Title::newFromRow( $r );
65 $title->getPrefixedText(),
75 private function initGroupsFromConf( array $cacheData ): array {
80 foreach ( $cacheData as $conf ) {
81 $groupIds[] = MessageBundleMessageGroup::getGroupId( $conf[0] );
85 TranslateMetadata::preloadGroups( $groupIds, __METHOD__ );
88 foreach ( $groupIds as $index => $groupId ) {
89 $conf = $cacheData[$index];
90 $description = $this->getMetadata( $groupId,
'description' );
91 $label = $this->getMetadata( $groupId,
'label' );
92 $groups[$groupId] =
new MessageBundleMessageGroup(
107 $this->groups = null;
108 $this->cache->touchKey();
110 $cacheData = $this->cache->getValue(
'recache' );
111 $this->groups = $this->initGroupsFromConf( $cacheData );
116 $this->groups = null;
117 $this->cache->delete();
120 private function getMetadata(
string $groupId,
string $key ): ?string {
122 return $metadata !==
false ? $metadata :
null;