2014-08-16 07:00:08 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 20:14:24 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Cache;
|
|
|
|
|
2024-03-17 20:10:34 +00:00
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2024-02-13 18:55:34 +00:00
|
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
2019-04-17 15:46:06 +00:00
|
|
|
|
2014-08-16 07:00:08 +00:00
|
|
|
/**
|
2019-04-17 15:46:06 +00:00
|
|
|
* Cache class that maps revision id to RevisionStore object
|
2023-08-14 15:36:07 +00:00
|
|
|
* @xxx Like TitleLocalCache, this class shouldn't need to exist.
|
2014-08-16 07:00:08 +00:00
|
|
|
*/
|
2022-11-02 20:14:24 +00:00
|
|
|
class RevisionLocalCache extends LocalCache {
|
2024-02-13 18:55:34 +00:00
|
|
|
private IConnectionProvider $dbProvider;
|
2024-03-17 20:10:34 +00:00
|
|
|
private RevisionStore $revisionStore;
|
2024-02-13 18:55:34 +00:00
|
|
|
|
2024-03-17 20:10:34 +00:00
|
|
|
public function __construct(
|
|
|
|
IConnectionProvider $dbProvider,
|
|
|
|
RevisionStore $revisionStore
|
|
|
|
) {
|
2024-02-13 18:55:34 +00:00
|
|
|
parent::__construct();
|
|
|
|
$this->dbProvider = $dbProvider;
|
2024-03-17 20:10:34 +00:00
|
|
|
$this->revisionStore = $revisionStore;
|
2024-02-13 18:55:34 +00:00
|
|
|
}
|
|
|
|
|
2014-08-16 07:00:08 +00:00
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @inheritDoc
|
2014-08-16 07:00:08 +00:00
|
|
|
*/
|
cache: Reduce responsibility of subclass and remove unused parts
* Reduce responsibility of resolve() methods to only supplying
the resolves values.
Moved logic for populating the cache and clearing the queue
to the base class, and made 'lookups' private.
* The second parameter to LocalCache::add() is unused, and never passed.
Removed to avoid confusion.
* The getTargets() method is unused. Removed.
* The getLookups() method is unused. Removed.
* The internal 'lookups' member was being used both for its keys and its
values, but never at the same time. This seemed risky, especially in
EchoRevisionLocalCache::resolve() where the associative array was passed
directly to the 'where' clause of IDatabase::select(), which shouldn't
espect keys when creating the 'IN' clause.
Using only values would keep value types flexible, but would require
use of the less efficient in_array().
Keeping both keys and values and calling array_values() would work.
Using only keys also works and is simpler, so long only ints are used.
* The tests were swapping 'targets' MapCacheLRU with a HashBagOStuff.
Following-up 4939bff7, this was forgotten, but works because the two
called methods (get and set) exist in both, but still seems odd.
Fixed by using TestingAccessWrapper to act on the existing object
instead of swapping it out.
* Improved tests by asserting more of the observed behaviour and impact.
Change-Id: I530eeac8bf3b407b8c633e0e20c7d35cc49f7a9f
2018-08-17 01:45:57 +00:00
|
|
|
protected function resolve( array $lookups ) {
|
2024-02-13 18:55:34 +00:00
|
|
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
2024-03-17 20:10:34 +00:00
|
|
|
$revQuery = $this->revisionStore->getQueryInfo( [ 'page', 'user' ] );
|
2024-04-27 21:37:18 +00:00
|
|
|
$res = $dbr->newSelectQueryBuilder()
|
|
|
|
->queryInfo( $revQuery )
|
|
|
|
->where( [ 'rev_id' => $lookups ] )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->fetchResultSet();
|
cache: Reduce responsibility of subclass and remove unused parts
* Reduce responsibility of resolve() methods to only supplying
the resolves values.
Moved logic for populating the cache and clearing the queue
to the base class, and made 'lookups' private.
* The second parameter to LocalCache::add() is unused, and never passed.
Removed to avoid confusion.
* The getTargets() method is unused. Removed.
* The getLookups() method is unused. Removed.
* The internal 'lookups' member was being used both for its keys and its
values, but never at the same time. This seemed risky, especially in
EchoRevisionLocalCache::resolve() where the associative array was passed
directly to the 'where' clause of IDatabase::select(), which shouldn't
espect keys when creating the 'IN' clause.
Using only values would keep value types flexible, but would require
use of the less efficient in_array().
Keeping both keys and values and calling array_values() would work.
Using only keys also works and is simpler, so long only ints are used.
* The tests were swapping 'targets' MapCacheLRU with a HashBagOStuff.
Following-up 4939bff7, this was forgotten, but works because the two
called methods (get and set) exist in both, but still seems odd.
Fixed by using TestingAccessWrapper to act on the existing object
instead of swapping it out.
* Improved tests by asserting more of the observed behaviour and impact.
Change-Id: I530eeac8bf3b407b8c633e0e20c7d35cc49f7a9f
2018-08-17 01:45:57 +00:00
|
|
|
foreach ( $res as $row ) {
|
2024-03-17 20:10:34 +00:00
|
|
|
yield $row->rev_id => $this->revisionStore->newRevisionFromRow( $row );
|
2014-08-16 07:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|