20 private const CACHE_KEY =
'messageBundle';
21 private const CACHE_VERSION = 1;
32 $this->cache = $cache;
35 'key' => self::CACHE_KEY,
36 'version' => self::CACHE_VERSION,
37 'regenerator' =>
function () {
38 return $this->getCacheData();
46 if ( $this->groups === null ) {
47 $cacheData = $this->cache->getValue();
48 $this->groups = $this->initGroupsFromConf( $cacheData );
54 public function getCacheData(): array {
56 $tables = [
'page',
'revtag' ];
57 $vars = [
'page_id',
'page_namespace',
'page_title',
'rt_revision' =>
'MAX(rt_revision)' ];
58 $conds = [
'page_id=rt_page',
'rt_type' => RevTagStore::MB_VALID_TAG ];
60 'GROUP BY' =>
'page_id,page_namespace,page_title'
62 $res = $this->db->select( $tables, $vars, $conds, __METHOD__, $options );
64 foreach ( $res as $r ) {
65 $title = Title::newFromRow( $r );
67 $title->getPrefixedText(),
77 private function initGroupsFromConf( array $cacheData ): array {
82 foreach ( $cacheData as $conf ) {
83 $groupIds[] = MessageBundleMessageGroup::getGroupId( $conf[0] );
87 TranslateMetadata::preloadGroups( $groupIds, __METHOD__ );
90 foreach ( $groupIds as $index => $groupId ) {
91 $conf = $cacheData[$index];
92 $description = TranslateMetadata::get( $groupId,
'description' );
93 $description = $description !==
false ? $description :
null;
94 $groups[$groupId] =
new MessageBundleMessageGroup( $groupId, $conf[0], $conf[1], $conf[2], $description );
102 $this->groups = null;
103 $this->cache->touchKey();
105 $cacheData = $this->cache->getValue(
'recache' );
106 $this->groups = $this->initGroupsFromConf( $cacheData );
111 $this->groups = null;
112 $this->cache->delete();