Fix static cache access

Currently, DT is making more than 30 exact queries back to back in every
request. It is clear the caching is completely broken.

It is because when the properties don't exist (majority of the cases),
it returns an empty array making the caching noop.

Tested in mwdebug1002 and it fixes the issue.

Bug: T364693
Change-Id: I182ae121999df1a04cfb7399bc49891587a37074
This commit is contained in:
Amir Sarabadani 2024-05-12 18:00:43 +02:00
parent 52ca3d408e
commit 320da37512

View file

@ -92,18 +92,22 @@ class HookUtils {
*/
public static function hasPagePropCached( Title $title, string $prop ): bool {
Assert::parameter(
in_array( $prop, static::CACHED_PAGE_PROPS, true ),
in_array( $prop, self::CACHED_PAGE_PROPS, true ),
'$prop',
'must be one of the cached properties'
);
$id = $title->getArticleId();
if ( !isset( static::$propCache[ $id ] ) ) {
if ( !isset( self::$propCache[ $id ] ) ) {
$services = MediaWikiServices::getInstance();
// Always fetch all of our properties, we need to check several of them on most requests
static::$propCache +=
$services->getPageProps()->getProperties( $title, static::CACHED_PAGE_PROPS );
$pagePropsPerId = $services->getPageProps()->getProperties( $title, self::CACHED_PAGE_PROPS );
if ( $pagePropsPerId ) {
self::$propCache += $pagePropsPerId;
} else {
self::$propCache[ $id ] = [];
}
}
return isset( static::$propCache[ $id ][ $prop ] );
return isset( self::$propCache[ $id ][ $prop ] );
}
/**