use MediaWiki\Revision\SlotRecord;
use MediaWiki\User\UserIdentity;
use MessageCache;
+use MWCallableUpdate;
use ParserCache;
use ParserOptions;
use ParserOutput;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
use RecentChangesUpdateJob;
use ResourceLoaderWikiModule;
use Revision;
use Title;
use User;
use Wikimedia\Assert\Assert;
-use Wikimedia\Rdbms\LBFactory;
+use Wikimedia\Rdbms\ILBFactory;
use WikiPage;
/**
* @since 1.32
* @ingroup Page
*/
-class DerivedPageDataUpdater implements IDBAccessObject {
+class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
/**
* @var UserIdentity|null
private $messageCache;
/**
- * @var LBFactory
+ * @var ILBFactory
*/
private $loadbalancerFactory;
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
/**
* @var string see $wgArticleCountMethod
*/
* @param JobQueueGroup $jobQueueGroup
* @param MessageCache $messageCache
* @param Language $contLang
- * @param LBFactory $loadbalancerFactory
+ * @param ILBFactory $loadbalancerFactory
*/
public function __construct(
WikiPage $wikiPage,
JobQueueGroup $jobQueueGroup,
MessageCache $messageCache,
Language $contLang,
- LBFactory $loadbalancerFactory
+ ILBFactory $loadbalancerFactory
) {
$this->wikiPage = $wikiPage;
// XXX only needed for waiting for replicas to catch up; there should be a narrower
// interface for that.
$this->loadbalancerFactory = $loadbalancerFactory;
+ $this->logger = new NullLogger();
+ }
+
+ public function setLogger( LoggerInterface $logger ) {
+ $this->logger = $logger;
}
/**
}
}
- /**
- * @return bool|string
- */
- private function getWikiId() {
- // TODO: get from RevisionStore
- return false;
- }
-
/**
* Checks whether this DerivedPageDataUpdater can be re-used for running updates targeting
* the given revision.
if ( $stashedEdit ) {
/** @var ParserOutput $output */
$output = $stashedEdit->output;
-
// TODO: this should happen when stashing the ParserOutput, not now!
$output->setCacheTime( $stashedEdit->timestamp );
$renderHints['known-revision-output'] = $output;
+
+ $this->logger->debug( __METHOD__ . ': using stashed edit output...' );
}
// NOTE: we want a canonical rendering, so don't pass $this->user or ParserOptions
}
// Defer the getCannonicalParserOutput() call triggered by getSecondaryDataUpdates()
- DeferredUpdates::addCallableUpdate( function () {
- $this->doSecondaryDataUpdates( [
- // T52785 do not update any other pages on a null edit
- 'recursive' => $this->options['changed']
- ] );
- } );
+ // by wrapping the code that schedules the secondary updates in a callback itself
+ $wrapperUpdate = new MWCallableUpdate(
+ function () {
+ $this->doSecondaryDataUpdates( [
+ // T52785 do not update any other pages on a null edit
+ 'recursive' => $this->options['changed']
+ ] );
+ },
+ __METHOD__
+ );
+ $wrapperUpdate->setTransactionRoundRequirement( $wrapperUpdate::TRX_ROUND_ABSENT );
+ DeferredUpdates::addUpdate( $wrapperUpdate );
// TODO: MCR: check if *any* changed slot supports categories!
if ( $this->rcWatchCategoryMembership
// TODO: In the wiring, register a listener for this on the new PageEventEmitter
ResourceLoaderWikiModule::invalidateModuleCache(
- $title, $oldLegacyRevision, $legacyRevision, $this->getWikiId() ?: wfWikiID()
+ $title,
+ $oldLegacyRevision,
+ $legacyRevision,
+ $this->loadbalancerFactory->getLocalDomainID()
);
$this->doTransition( 'done' );
* current page or otherwise depend on it (default: false)
* - defer: one of the DeferredUpdates constants, or false to run immediately after waiting
* for replication of the changes from the SecondaryDataUpdates hooks (default: false)
- * - transactionTicket: a transaction ticket from LBFactory::getEmptyTransactionTicket(),
- * only when defer is false (default: null)
* @since 1.32
*/
public function doSecondaryDataUpdates( array $options = [] ) {
$this->assertHasRevision( __METHOD__ );
- $options += [
- 'recursive' => false,
- 'defer' => false,
- 'transactionTicket' => null,
- ];
+ $options += [ 'recursive' => false, 'defer' => false ];
$deferValues = [ false, DeferredUpdates::PRESEND, DeferredUpdates::POSTSEND ];
if ( !in_array( $options['defer'], $deferValues, true ) ) {
- throw new InvalidArgumentException( 'invalid value for defer: ' . $options['defer'] );
+ throw new InvalidArgumentException( 'Invalid value for defer: ' . $options['defer'] );
}
- Assert::parameterType( 'integer|null', $options['transactionTicket'],
- '$options[\'transactionTicket\']' );
-
$updates = $this->getSecondaryDataUpdates( $options['recursive'] );
$triggeringUser = $this->options['triggeringUser'] ?? $this->user;
$causeAgent = $this->options['causeAgent'] ?? 'unknown';
$legacyRevision = new Revision( $this->revision );
- if ( $options['defer'] === false && $options['transactionTicket'] !== null ) {
- // For legacy hook handlers doing updates via LinksUpdateConstructed, make sure
- // any pending writes they made get flushed before the doUpdate() calls below.
- // This avoids snapshot-clearing errors in LinksUpdate::acquirePageLock().
- $this->loadbalancerFactory->commitAndWaitForReplication(
- __METHOD__, $options['transactionTicket']
- );
- }
-
foreach ( $updates as $update ) {
if ( $update instanceof DataUpdate ) {
$update->setCause( $causeAction, $causeAgent );
$update->setRevision( $legacyRevision );
$update->setTriggeringUser( $triggeringUser );
}
+ }
- if ( $options['defer'] === false ) {
- if ( $update instanceof DataUpdate && $options['transactionTicket'] !== null ) {
- $update->setTransactionTicket( $options['transactionTicket'] );
- }
- $update->doUpdate();
- } else {
+ if ( $options['defer'] === false ) {
+ // T221577: flush any transaction; each update needs outer transaction scope
+ $this->loadbalancerFactory->commitMasterChanges( __METHOD__ );
+ foreach ( $updates as $update ) {
+ DeferredUpdates::attemptUpdate( $update, $this->loadbalancerFactory );
+ }
+ } else {
+ foreach ( $updates as $update ) {
DeferredUpdates::addUpdate( $update, $options['defer'] );
}
}