mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-13 18:37:07 +00:00
HookUtils: Fetch all needed props in one query
Bug: T347123 Change-Id: I54e5dfeb8ee07f0c3b6df4bffd2c6112cc1ad145
This commit is contained in:
parent
7a1337e430
commit
b4def00ed0
|
@ -75,7 +75,13 @@ class HookUtils {
|
||||||
self::REPLYTOOL,
|
self::REPLYTOOL,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static array $propCache = [];
|
private const CACHED_PAGE_PROPS = [
|
||||||
|
'newsectionlink',
|
||||||
|
'nonewsectionlink',
|
||||||
|
'notalk',
|
||||||
|
'archivedtalk',
|
||||||
|
];
|
||||||
|
private static array $propCache = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a title has a page prop, and use an in-memory cache to avoid extra queries
|
* Check if a title has a page prop, and use an in-memory cache to avoid extra queries
|
||||||
|
@ -85,16 +91,19 @@ class HookUtils {
|
||||||
* @return bool Title has page property
|
* @return bool Title has page property
|
||||||
*/
|
*/
|
||||||
public static function hasPagePropCached( Title $title, string $prop ): bool {
|
public static function hasPagePropCached( Title $title, string $prop ): bool {
|
||||||
|
Assert::parameter(
|
||||||
|
in_array( $prop, static::CACHED_PAGE_PROPS, true ),
|
||||||
|
'$prop',
|
||||||
|
'must be one of the cached properties'
|
||||||
|
);
|
||||||
$id = $title->getArticleId();
|
$id = $title->getArticleId();
|
||||||
if ( !isset( static::$propCache[ $id ] ) ) {
|
if ( !isset( static::$propCache[ $id ] ) ) {
|
||||||
static::$propCache[ $id ] = [];
|
|
||||||
}
|
|
||||||
if ( !isset( static::$propCache[ $id ][ $prop ] ) ) {
|
|
||||||
$services = MediaWikiServices::getInstance();
|
$services = MediaWikiServices::getInstance();
|
||||||
$props = $services->getPageProps()->getProperties( $title, $prop );
|
// Always fetch all of our properties, we need to check several of them on most requests
|
||||||
static::$propCache[ $id ][ $prop ] = isset( $props[ $id ] );
|
static::$propCache[ $id ] =
|
||||||
|
$services->getPageProps()->getProperties( $title, static::CACHED_PAGE_PROPS );
|
||||||
}
|
}
|
||||||
return static::$propCache[ $id ][ $prop ];
|
return isset( static::$propCache[ $id ][ $prop ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue