[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
Daniel Kinzler has uploaded a new change for review. https://gerrit.wikimedia.org/r/222463 Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. FIXME: I was unable to verify that this works. I see the jobs in the database, but I cannot get them to run for some reason. runJobs.php does nothing. Bug: 103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 444 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/63/222463/1 diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 4c48108..6d5305f 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -123,6 +123,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][]= '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsageForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..4ac6a07 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,20 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache updates may be triggered by page views (in a new language), + // schedule the usage updates in the job queue, to avoid writing to the database + // during a GET request. + + $addUsagesForPageJob = AddUsagesForPageJob::new
[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
Aude has submitted this change and it was merged. Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. Bug: T103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 449 insertions(+), 28 deletions(-) Approvals: Aude: Verified; Looks good to me, approved Addshore: Looks good to me, but someone else must approve diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 6fb840c..9a9ae33 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -67,6 +67,7 @@ global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; global $wgAPIMetaModules, $wgAPIPropModules, $wgSpecialPages, $wgResourceModules; global $wgWBClientSettings, $wgRecentChangesFlags, $wgMessagesDirs; + global $wgJobClasses; $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, @@ -121,6 +122,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][] = '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsagesForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..42d9d78 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,22 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache updates may be triggered by page views (in a new language), + // schedule
[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/227632 Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. Bug: T103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 (cherry picked from commit 2bdd21e427cac4f0f5a2a5cdcdd4a276633d7866) --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 449 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/32/227632/1 diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 6fb840c..9a9ae33 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -67,6 +67,7 @@ global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; global $wgAPIMetaModules, $wgAPIPropModules, $wgSpecialPages, $wgResourceModules; global $wgWBClientSettings, $wgRecentChangesFlags, $wgMessagesDirs; + global $wgJobClasses; $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, @@ -121,6 +122,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][] = '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsagesForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..42d9d78 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,22 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache upd
[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/227634 Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. Bug: T103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 448 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/34/227634/1 diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 4c48108..deefc1f 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -67,6 +67,7 @@ global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; global $wgAPIMetaModules, $wgAPIPropModules, $wgSpecialPages, $wgResourceModules; global $wgWBClientSettings, $wgRecentChangesFlags, $wgMessagesDirs; + global $wgJobClasses; $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, @@ -123,6 +124,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][]= '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsagesForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..42d9d78 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,22 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache updates may be triggered by page views (in a new
[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
Aude has submitted this change and it was merged. Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. Bug: T103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 (cherry picked from commit 2bdd21e427cac4f0f5a2a5cdcdd4a276633d7866) --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 449 insertions(+), 28 deletions(-) Approvals: Aude: Verified; Looks good to me, approved diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 6fb840c..9a9ae33 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -67,6 +67,7 @@ global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; global $wgAPIMetaModules, $wgAPIPropModules, $wgSpecialPages, $wgResourceModules; global $wgWBClientSettings, $wgRecentChangesFlags, $wgMessagesDirs; + global $wgJobClasses; $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, @@ -121,6 +122,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][] = '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsagesForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..42d9d78 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,22 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache updates may be triggered by page views (in a new language), + //
[MediaWiki-commits] [Gerrit] On page views, update usage tracking via the job queue. - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: On page views, update usage tracking via the job queue. .. On page views, update usage tracking via the job queue. In some cases, we need to update the usage tracking table during normal page views. In this case, we should not write to the database directly, but schedule a job instead. Bug: T103429 Change-Id: Ied1db3f2ab802ac7d7638b63844598374bd59812 --- M client/WikibaseClient.php M client/includes/Hooks/DataUpdateHookHandlers.php M client/includes/Usage/EntityUsage.php A client/includes/store/AddUsagesForPageJob.php M client/includes/store/ClientStore.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/MockClientStore.php A client/tests/phpunit/includes/AddUsagesForPageJobTest.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php M client/tests/phpunit/includes/Usage/EntityUsageTest.php 10 files changed, 448 insertions(+), 28 deletions(-) Approvals: Aude: Looks good to me, approved jenkins-bot: Verified diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php index 4c48108..deefc1f 100644 --- a/client/WikibaseClient.php +++ b/client/WikibaseClient.php @@ -67,6 +67,7 @@ global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgHooks; global $wgAPIMetaModules, $wgAPIPropModules, $wgSpecialPages, $wgResourceModules; global $wgWBClientSettings, $wgRecentChangesFlags, $wgMessagesDirs; + global $wgJobClasses; $wgExtensionCredits['wikibase'][] = array( 'path' => __DIR__, @@ -123,6 +124,9 @@ // extension hooks $wgHooks['WikibaseDeleteData'][]= '\Wikibase\ClientHooks::onWikibaseDeleteData'; + // job classes + $wgJobClasses['wikibase-addUsagesForPage'] = 'Wikibase\Client\Store\AddUsagesForPageJob'; + // api modules $wgAPIMetaModules['wikibase'] = array( 'class' => 'Wikibase\ApiClientInfo', diff --git a/client/includes/Hooks/DataUpdateHookHandlers.php b/client/includes/Hooks/DataUpdateHookHandlers.php index 8b12966..42d9d78 100644 --- a/client/includes/Hooks/DataUpdateHookHandlers.php +++ b/client/includes/Hooks/DataUpdateHookHandlers.php @@ -3,6 +3,8 @@ namespace Wikibase\Client\Hooks; use Content; +use JobQueueGroup; +use JobSpecification; use LinksUpdate; use ManualLogEntry; use ParserCache; @@ -10,7 +12,9 @@ use ParserOutput; use Title; use User; +use Wikibase\Client\Store\AddUsagesForPageJob; use Wikibase\Client\Store\UsageUpdater; +use Wikibase\Client\Usage\EntityUsage; use Wikibase\Client\Usage\ParserOutputUsageAccumulator; use Wikibase\Client\WikibaseClient; use WikiPage; @@ -34,19 +38,15 @@ */ private $usageUpdater; + /** +* @var JobQueueGroup +*/ + private $jobScheduler; + public static function newFromGlobalState() { - $wikibaseClient = WikibaseClient::getDefaultInstance(); - $settings = $wikibaseClient->getSettings(); - - $usageUpdater = new UsageUpdater( - $settings->getSetting( 'siteGlobalID' ), - $wikibaseClient->getStore()->getUsageTracker(), - $wikibaseClient->getStore()->getUsageLookup(), - $wikibaseClient->getStore()->getSubscriptionManager() - ); - return new DataUpdateHookHandlers( - $usageUpdater + WikibaseClient::getDefaultInstance()->getStore()->getUsageUpdater(), + JobQueueGroup::singleton() ); } @@ -113,9 +113,11 @@ } public function __construct( - UsageUpdater $usageUpdater + UsageUpdater $usageUpdater, + JobQueueGroup $jobScheduler ) { $this->usageUpdater = $usageUpdater; + $this->jobScheduler = $jobScheduler; } /** @@ -169,13 +171,22 @@ // These timestamps should usually be the same, but asking $title may cause a database query. $touched = $parserOutput->getTimestamp() ?: $title->getTouched(); + if ( count( $usageAcc->getUsages() ) === 0 ) { + // no usages, bail out + return; + } + // Add or touch any usages present in the new rendering. // This allows us to track usages in each user language separately, for multilingual sites. - $this->usageUpdater->addUsagesForPage( - $title->getArticleId(), - $usageAcc->getUsages(), - $touched - ); + + // NOTE: Since parser cache updates may be triggered by page views (in a new language), + // schedule the usage updat