summaryrefslogtreecommitdiff
blob: 4c8c31a63d36582793e73c3debfdbff0bfc090d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

use MediaWiki\MediaWikiServices;

/**
 * Cache class that maps revision id to RevisionStore object
 */
class EchoRevisionLocalCache extends EchoLocalCache {

	/**
	 * @var EchoRevisionLocalCache
	 */
	private static $instance;

	/**
	 * @return EchoRevisionLocalCache
	 */
	public static function create() {
		if ( !self::$instance ) {
			self::$instance = new EchoRevisionLocalCache();
		}

		return self::$instance;
	}

	/**
	 * @inheritDoc
	 */
	protected function resolve( array $lookups ) {
		$store = MediaWikiServices::getInstance()->getRevisionStore();
		$dbr = wfGetDB( DB_REPLICA );
		$revQuery = $store->getQueryInfo( [ 'page', 'user' ] );
		$res = $dbr->select(
			$revQuery['tables'],
			$revQuery['fields'],
			[ 'rev_id' => $lookups ],
			__METHOD__,
			[],
			$revQuery['joins']
		);
		foreach ( $res as $row ) {
			yield $row->rev_id => $store->newRevisionFromRow( $row );
		}
	}
}