public function testFindPartialEmbeddedQueryTargetLinksHashListFor()
 {
     $row = new \stdClass();
     $row->s_id = 1001;
     $idTable = $this->getMockBuilder('\\stdClass')->setMethods(array('getDataItemPoolHashListFor'))->getMock();
     $idTable->expects($this->once())->method('getDataItemPoolHashListFor');
     $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
     $connection->expects($this->once())->method('select')->with($this->equalTo(\SMWSQLStore3::QUERY_LINKS_TABLE), $this->anything(), $this->equalTo(array('o_id' => array(42))))->will($this->returnValue(array($row)));
     $connectionManager = $this->getMockBuilder('\\SMW\\ConnectionManager')->disableOriginalConstructor()->getMock();
     $connectionManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->setMethods(array('getObjectIds'))->getMockForAbstractClass();
     $store->setConnectionManager($connectionManager);
     $store->expects($this->any())->method('getObjectIds')->will($this->returnValue($idTable));
     $dependencyLinksTableUpdater = $this->getMockBuilder('\\SMW\\SQLStore\\QueryDependency\\DependencyLinksTableUpdater')->disableOriginalConstructor()->getMock();
     $dependencyLinksTableUpdater->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $queryResultDependencyListResolver = $this->getMockBuilder('\\SMW\\SQLStore\\QueryDependency\\QueryResultDependencyListResolver')->disableOriginalConstructor()->getMock();
     $instance = new QueryDependencyLinksStore($queryResultDependencyListResolver, $dependencyLinksTableUpdater);
     $requestOptions = new RequestOptions();
     $requestOptions->setLimit(1);
     $requestOptions->setOffset(200);
     $instance->findEmbeddedQueryTargetLinksHashListFor(array(42), $requestOptions);
 }
 public function testOffset()
 {
     $instance = new RequestOptions();
     $instance->setOffset(42);
     $this->assertEquals(42, $instance->getOffset());
 }
 /**
  * Based on the CHUNK_SIZE, target links are purged in an instant if those
  * selected entities are < CHUNK_SIZE which should be enough for most
  * common queries that only share a limited amount of dependencies, yet for
  * queries that expect a large subject/dependency pool, doing an online update
  * for all at once is not feasible hence the iterative process of creating
  * batches that run through the job scheduler.
  *
  * @param array|string $idList
  */
 private function findEmbeddedQueryTargetLinksBatches($idList)
 {
     if (is_string($idList) && strpos($idList, '|') !== false) {
         $idList = explode('|', $idList);
     }
     if ($idList === array()) {
         return true;
     }
     $queryDependencyLinksStoreFactory = new QueryDependencyLinksStoreFactory();
     $queryDependencyLinksStore = $queryDependencyLinksStoreFactory->newQueryDependencyLinksStore($this->store);
     $requestOptions = new RequestOptions();
     // +1 to look ahead
     $requestOptions->setLimit($this->limit + 1);
     $requestOptions->setOffset($this->offset);
     $hashList = $queryDependencyLinksStore->findEmbeddedQueryTargetLinksHashListFor($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) {
         $job = new self($this->getTitle(), array('idlist' => $idList, 'limit' => $this->limit, 'offset' => $this->offset + self::CHUNK_SIZE));
         $job->run();
     }
     wfDebugLog('smw', __METHOD__ . " counted: {$countedHashListEntries} | offset: {$this->offset}  for " . $this->getTitle()->getPrefixedDBKey() . "\n");
     list($hashList, $queryList) = $this->doBuildUniqueTargetLinksHashList($hashList);
     $this->applicationFactory->singleton('CachedQueryResultPrefetcher')->resetCacheBy($queryList);
     $this->addPagesToUpdater($hashList);
 }