Page MenuHomePhabricator

Migrate EntityRevisionLookup to service container
Closed, ResolvedPublic

Description

The EntityRevisionLookup service in Multi/SingleEntitySourceServices (DataAccessServices) should be migrated to the new service wiring files in repo and client respectively. (See docs on how to migrate services into the new service container)

This will allow us to stop passing a SingleEntitySourceServicesFactory into PrefetchingTermLookupFactory, and will finally allow us to remove the SingleEntitySourceServiceFactory service (T277731).

The SingleEntitySourceServices method getEntityRevisionLookup is bound to one entity source, so we might want to also create a kind of EntityRevisionLookupFactory, which is given an entity source (or its database name?) and returns a EntityRevisionLookup.

Event Timeline

The SingleEntitySourceServices method getEntityRevisionLookup is bound to one entity source, so we might want to also create a kind of EntityRevisionLookupFactory, which is given an entity source (or its database name?) and returns a EntityRevisionLookup.

I’m not sure we actually need this. In Repo, we already have an EntityRevisionLookup service, and it seems to work fine for all entity types as far as I can tell, including on Commons for MediaInfo entities (local) as well as Items (other entity source). In Client, the service doesn’t directly exist yet, but you can get it from the Store service, and the lookup from there likewise seems to support all entity types.

I think we can just add the store lookup directly to the client service container, use that in the .entitytypes.php files, and thus remove the need for the SingleEntitySourceServicesFactory. Ideally, test this on mwdebug before it rolls out with the train (perhaps even before merging) – next week (no regular train) might be a good opportunity for this.

I just tested the following diffs on mwdebug1002:

Wikibase.git
diff --git a/client/WikibaseClient.entitytypes.php b/client/WikibaseClient.entitytypes.php
index d3f5ddc8d5..f4705c2287 100644
--- a/client/WikibaseClient.entitytypes.php
+++ b/client/WikibaseClient.entitytypes.php
@@ -40,8 +40,6 @@
 	'property' => [
 		Def::PREFETCHING_TERM_LOOKUP_CALLBACK => function ( DatabaseEntitySource $entitySource ) {
 			$mwServices = MediaWikiServices::getInstance();
-			$entitySourceServices = WikibaseClient::getSingleEntitySourceServicesFactory( $mwServices )
-				->getServicesForSource( $entitySource );
 
 			$cacheSecret = hash( 'sha256', $mwServices->getMainConfig()->get( 'SecretKey' ) );
 			$bagOStuff = $mwServices->getLocalServerObjectCache();
@@ -69,7 +67,7 @@
 				]
 			);
 			$redirectResolvingRevisionLookup = new RedirectResolvingLatestRevisionLookup(
-				$entitySourceServices->getEntityRevisionLookup()
+				WikibaseClient::getStore( $mwServices )->getEntityRevisionLookup()
 			);
 
 			return new CachingPrefetchingTermLookup(
diff --git a/repo/WikibaseRepo.entitytypes.php b/repo/WikibaseRepo.entitytypes.php
index c8c2d11bf2..6480726d4c 100644
--- a/repo/WikibaseRepo.entitytypes.php
+++ b/repo/WikibaseRepo.entitytypes.php
@@ -464,8 +464,6 @@
 		},
 		Def::PREFETCHING_TERM_LOOKUP_CALLBACK => function ( DatabaseEntitySource $entitySource ) {
 			$mwServices = MediaWikiServices::getInstance();
-			$entitySourceServices = WikibaseRepo::getSingleEntitySourceServicesFactory( $mwServices )
-				->getServicesForSource( $entitySource );
 
 			$cacheSecret = hash( 'sha256', $mwServices->getMainConfig()->get( 'SecretKey' ) );
 			$bagOStuff = $mwServices->getLocalServerObjectCache();
@@ -493,7 +491,7 @@
 				]
 			);
 			$redirectResolvingRevisionLookup = new RedirectResolvingLatestRevisionLookup(
-				$entitySourceServices->getEntityRevisionLookup()
+				WikibaseRepo::getEntityRevisionLookup( $mwServices )
 			);
 
 			return new CachingPrefetchingTermLookup(
WikibaseMediaInfo.git
diff --git a/WikibaseMediaInfo.entitytypes.php b/WikibaseMediaInfo.entitytypes.php
index 4b8e98e96f..779a90468b 100644
--- a/WikibaseMediaInfo.entitytypes.php
+++ b/WikibaseMediaInfo.entitytypes.php
@@ -320,10 +320,7 @@
 			);
 		},
 		Def::PREFETCHING_TERM_LOOKUP_CALLBACK => static function ( EntitySource $entitySource ) {
-			$services = WikibaseRepo::getSingleEntitySourceServicesFactory()
-					->getServicesForSource( $entitySource );
-
-			return new MediaInfoPrefetchingTermLookup( $services->getEntityRevisionLookup() );
+			return new MediaInfoPrefetchingTermLookup( WikibaseRepo::getEntityRevisionLookup() );
 		},
 		Def::ENTITY_ID_LOOKUP_CALLBACK => static function () {
 			return MediaInfoServices::getMediaInfoIdLookup();

And as far as I can tell, everything worked fine; there aren’t any unusual messages in the mwdebug logstash either. I think we can really just add the EntityRevisionLookup to the client service container (just like the repo one: get it from the Store service), use that instead of the one from the $entitySourceServices, then see how much of the SingleEntitySourceServicesFactory that lets us remove.

Change 814146 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Add EntityRevisionLookup to client service container

https://gerrit.wikimedia.org/r/814146

Change 814148 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Math@master] Get EntityRevisionLookup from WikibaseClient services

https://gerrit.wikimedia.org/r/814148

Change 814146 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Add EntityRevisionLookup to client service container

https://gerrit.wikimedia.org/r/814146

Change 814148 abandoned by Physikerwelt:

[mediawiki/extensions/Math@master] Get EntityRevisionLookup from WikibaseClient services

Reason:

Replaced by I38d6425eb5e2c52ae4362c4b8656223a8d9d90a5

https://gerrit.wikimedia.org/r/814148