Skip to content

Commit

Permalink
ParserCachePurgeJob count links from the source (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Apr 2, 2017
1 parent b4e0c65 commit adca833
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
29 changes: 19 additions & 10 deletions src/MediaWiki/Jobs/ParserCachePurgeJob.php
Expand Up @@ -9,6 +9,7 @@
use SMW\RequestOptions;
use SMWQuery as Query;
use Title;
use SMW\Utils\Timer;

/**
* @license GNU GPL v2+
Expand Down Expand Up @@ -62,8 +63,11 @@ public function __construct( Title $title, $params = array() ) {
*/
public function run() {

Timer::start( __METHOD__ );

$this->pageUpdater = $this->applicationFactory->newPageUpdater();
$this->store = $this->applicationFactory->getStore();
$logger = $this->applicationFactory->getMediaWikiLogger();

if ( $this->hasParameter( 'limit' ) ) {
$this->limit = $this->getParameter( 'limit' );
Expand All @@ -76,7 +80,7 @@ public function run() {
if ( $this->hasParameter( 'idlist' ) ) {
$this->findEmbeddedQueryTargetLinksBatches(
$this->getParameter( 'idlist' ),
$this->applicationFactory->getMediaWikiLogger()
$logger
);
}

Expand All @@ -86,6 +90,8 @@ public function run() {

Hooks::run( 'SMW::Job::AfterParserCachePurgeComplete', array( $this ) );

$logger->info( __METHOD__ . ' (procTime in sec: ' . Timer::getElapsedTime( __METHOD__, 7 ) . ')' );

return true;
}

Expand Down Expand Up @@ -120,22 +126,16 @@ private function findEmbeddedQueryTargetLinksBatches( $idList, $logger ) {
// +1 to look ahead
$requestOptions->setLimit( $this->limit + 1 );
$requestOptions->setOffset( $this->offset );
$requestOptions->targetLinksCount = 0;

$hashList = $queryDependencyLinksStore->findEmbeddedQueryTargetLinksHashListFrom(
$idList,
$requestOptions
);

if ( $hashList === array() ) {
return true;
}

$countedHashListEntries = count( $hashList );

// If more results are available then use an iterative increase to fetch
// the remaining updates by creating successive jobs
if ( $countedHashListEntries > $this->limit ) {

if ( $requestOptions->targetLinksCount > $this->limit ) {
$job = new self( $this->getTitle(), array(
'idlist' => $idList,
'limit' => $this->limit,
Expand All @@ -145,12 +145,21 @@ private function findEmbeddedQueryTargetLinksBatches( $idList, $logger ) {
$job->run();
}

$logger->info( __METHOD__ . " counted: {$countedHashListEntries} | offset: {$this->offset} for " . $this->getTitle()->getPrefixedDBKey() );
if ( $hashList === array() ) {
return true;
}

list( $hashList, $queryList ) = $this->doBuildUniqueTargetLinksHashList(
$hashList
);

$logger->info(
__METHOD__ .
" counted: " . count( $hashList ) .
" targetLinksCount: " . $requestOptions->targetLinksCount .
" (offset: {$this->offset} for " . $this->getTitle()->getPrefixedDBKey() . ")"
);

$this->applicationFactory->singleton( 'CachedQueryResultPrefetcher' )->resetCacheBy(
$queryList,
'ParserCachePurgeJob'
Expand Down
9 changes: 6 additions & 3 deletions src/SQLStore/QueryDependency/QueryDependencyLinksStore.php
Expand Up @@ -306,16 +306,19 @@ public function findEmbeddedQueryTargetLinksHashListFrom( array $idlist, Request
return array();
}

$requestOptions = new RequestOptions();
// Return the expected count of targets
$requestOptions->targetLinksCount = count( $targetLinksIdList );

$requestOptions->addExtraCondition(
$poolRequestOptions = new RequestOptions();

$poolRequestOptions->addExtraCondition(
'smw_iw !=' . $this->connection->addQuotes( SMW_SQL3_SMWREDIIW ) . ' AND '.
'smw_iw !=' . $this->connection->addQuotes( SMW_SQL3_SMWDELETEIW )
);

return $this->store->getObjectIds()->getDataItemPoolHashListFor(
$targetLinksIdList,
$requestOptions
$poolRequestOptions
);
}

Expand Down

0 comments on commit adca833

Please sign in to comment.