public function testLimit() { $instance = new RequestOptions(); $instance->setLimit(42); $this->assertEquals(42, $instance->getLimit()); }
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); }
/** * Get the HTML for displaying subproperties of this property. This list * is usually short and we implement no additional navigation. * * @return string */ protected function getSubpropertyList() { $more = false; $requestOptions = new RequestOptions(); $requestOptions->sort = true; $requestOptions->ascending = true; // +1 look-ahead $requestOptions->setLimit($GLOBALS['smwgSubPropertyListLimit'] + 1); $subproperties = $this->store->getPropertySubjects(new DIProperty('_SUBP'), $this->getDataItem(), $requestOptions); // Pop the +1 look-ahead from the list if (count($subproperties) > $GLOBALS['smwgSubPropertyListLimit']) { array_pop($subproperties); $more = true; } $result = ''; $resultCount = count($subproperties); if ($more) { $message = Html::rawElement('span', array('class' => 'plainlinks'), wfMessage('smw-subpropertylist-count-with-restricted-note', $resultCount, $GLOBALS['smwgSubPropertyListLimit'])->parse()); } else { $message = wfMessage('smw-subpropertylist-count', $resultCount)->text(); } if ($resultCount > 0) { $titleText = htmlspecialchars($this->mTitle->getText()); $result .= "<div id=\"mw-subcategories\">\n<h2>" . wfMessage('smw_subproperty_header', $titleText)->text() . "</h2>\n<p>"; if (!$this->mProperty->isUserDefined()) { $result .= wfMessage('smw_isspecprop')->text() . ' '; } $result .= $message . "</p>" . "\n"; if ($resultCount < 6) { $result .= SMWPageLister::getShortList(0, $resultCount, $subproperties, null); } else { $result .= SMWPageLister::getColumnList(0, $resultCount, $subproperties, null); } $result .= "\n</div>"; } return $result; }
/** * 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); }