22 private const CACHE_SIZE = 100;
24 private const ALL_PROPS_KEY = 0;
34 $this->linkBatchFactory = $linkBatchFactory;
35 $this->dbProvider = $dbProvider;
63 if ( is_array( $propertyNames ) ) {
66 $propertyNames = [ $propertyNames ];
71 $goodIDs = $this->getGoodIDs( $titles );
73 foreach ( $goodIDs as $pageID ) {
74 foreach ( $propertyNames as $propertyName ) {
75 $propertyValue = $this->getCachedProperty( $pageID, $propertyName );
76 if ( $propertyValue ===
null ) {
78 $queryIDs[$pageID] =
true;
81 $this->cache->setField( $pageID, $propertyName,
false );
82 } elseif ( $propertyValue !==
false ) {
84 $values[$pageID][$propertyName] = $propertyValue;
86 $values[$pageID] = $propertyValue;
93 $queryBuilder = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder();
94 $queryBuilder->select( [
'pp_page',
'pp_propname',
'pp_value' ] )
95 ->from(
'page_props' )
96 ->where( [
'pp_page' => array_keys( $queryIDs ),
'pp_propname' => $propertyNames ] )
97 ->caller( __METHOD__ );
98 $result = $queryBuilder->fetchResultSet();
100 foreach ( $result as $row ) {
101 $pageID = $row->pp_page;
102 $propertyName = $row->pp_propname;
103 $propertyValue = $row->pp_value;
104 $this->cache->setField( $pageID, $propertyName, $propertyValue );
106 $values[$pageID][$propertyName] = $propertyValue;
108 $values[$pageID] = $propertyValue;
135 $goodIDs = $this->getGoodIDs( $titles );
137 foreach ( $goodIDs as $pageID ) {
138 $pageProperties = $this->getCachedProperties( $pageID );
139 if ( $pageProperties ===
false ) {
140 $queryIDs[] = $pageID;
142 $values[$pageID] = $pageProperties;
147 $queryBuilder = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder();
148 $queryBuilder->select( [
'pp_page',
'pp_propname',
'pp_value' ] )
149 ->from(
'page_props' )
150 ->where( [
'pp_page' => $queryIDs ] )
151 ->caller( __METHOD__ );
152 $result = $queryBuilder->fetchResultSet();
155 $pageProperties = [];
156 foreach ( $result as $row ) {
157 $pageID = $row->pp_page;
158 if ( $currentPageID != $pageID ) {
159 if ( $pageProperties ) {
161 $this->cacheProperties( $currentPageID, $pageProperties );
162 $values[$currentPageID] = $pageProperties;
164 $currentPageID = $pageID;
165 $pageProperties = [];
167 $pageProperties[$row->pp_propname] = $row->pp_value;
169 if ( $pageProperties ) {
171 $this->cacheProperties( $pageID, $pageProperties );
173 $values[$pageID] = $pageProperties;
184 private function getGoodIDs( $titles ) {
186 if ( is_iterable( $titles ) ) {
188 ( is_array( $titles ) && reset( $titles ) instanceof
Title
194 $this->linkBatchFactory->newLinkBatch( $titles )->execute();
197 foreach ( $titles as $title ) {
200 if ( $title->canExist() ) {
201 $pageID = $title->getId();
210 if ( $titles->canExist() ) {
211 $pageID = $titles->getId();
227 private function getCachedProperty( $pageID, $propertyName ) {
228 if ( $this->cache->hasField( $pageID, $propertyName ) ) {
229 return $this->cache->getField( $pageID, $propertyName );
231 if ( $this->cache->hasField( self::ALL_PROPS_KEY, $pageID ) ) {
232 $pageProperties = $this->cache->getField( self::ALL_PROPS_KEY, $pageID );
233 if ( isset( $pageProperties[$propertyName] ) ) {
234 return $pageProperties[$propertyName];
246 private function getCachedProperties( $pageID ) {
247 if ( $this->cache->hasField( self::ALL_PROPS_KEY, $pageID ) ) {
248 return $this->cache->getField( self::ALL_PROPS_KEY, $pageID );
259 private function cacheProperties( $pageID, array $pageProperties ) {
261 $this->cache->clear( $pageID );
263 $this->cache->setField( self::ALL_PROPS_KEY, $pageID, $pageProperties );
270 $this->cache->
clear();