/** * @depends testRoundtripForRegisteredNamespace */ public function testVerifyRetainedReferenceFromPreviousInvocation() { $instance = new CircularReferenceGuard('bar'); $this->assertEquals(1, $instance->get('Foo')); $instance->reset('bar'); $this->assertEquals(0, $instance->get('Foo')); }
/** * @since 2.1 * * @return ShowParserFunction */ public function newShowParserFunction() { $circularReferenceGuard = new CircularReferenceGuard('show-parser'); $circularReferenceGuard->setMaxRecursionDepth(2); $parserData = ApplicationFactory::getInstance()->newParserData($this->parser->getTitle(), $this->parser->getOutput()); $messageFormatter = new MessageFormatter($this->parser->getTargetLanguage()); $instance = new ShowParserFunction($parserData, $messageFormatter, $circularReferenceGuard); return $instance; }
/** * @since 2.2 * * @return QueryEngine */ public function newMasterQueryEngine() { $circularReferenceGuard = new CircularReferenceGuard('sparql-query'); $circularReferenceGuard->setMaxRecursionDepth(2); $compoundConditionBuilder = new CompoundConditionBuilder(); $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard); $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), new EngineOptions()); return $queryEngine; }
/** * @since 2.2 * * @return QueryEngine */ public function newMasterQueryEngine() { $engineOptions = new EngineOptions(); $hierarchyFinder = new HierarchyFinder($this->store, ApplicationFactory::getInstance()->newCacheFactory()->newFixedInMemoryCache(500)); $circularReferenceGuard = new CircularReferenceGuard('sparql-query'); $circularReferenceGuard->setMaxRecursionDepth(2); $compoundConditionBuilder = new CompoundConditionBuilder($engineOptions); $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard); $compoundConditionBuilder->setHierarchyFinder($hierarchyFinder); $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions); return $queryEngine; }
/** * @since 2.2 * * @return QueryEngine */ public function newMasterQueryEngine() { $engineOptions = new EngineOptions(); $circularReferenceGuard = new CircularReferenceGuard('sparql-queryengine'); $circularReferenceGuard->setMaxRecursionDepth(2); $compoundConditionBuilder = new CompoundConditionBuilder(new DescriptionInterpreterFactory(), $engineOptions); $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard); $compoundConditionBuilder->setPropertyHierarchyLookup($this->applicationFactory->newPropertyHierarchyLookup()); $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions); $cachedQueryResultPrefetcher = ApplicationFactory::getInstance()->singleton('CachedQueryResultPrefetcher'); $cachedQueryResultPrefetcher->setQueryEngine($queryEngine); return $cachedQueryResultPrefetcher; }
/** * @since 2.5 * * @param $dataItem * * @return DataItem */ public function findRedirectTarget($dataItem) { if (!$dataItem instanceof DIWikiPage && !$dataItem instanceof DIProperty) { return $dataItem; } $hash = $dataItem->getSerialization(); // Guard against a dataItem that points to itself $this->circularReferenceGuard->mark($hash); if (!$this->circularReferenceGuard->isCircularByRecursionFor($hash)) { $dataItem = $this->store->getRedirectTarget($dataItem); } $this->circularReferenceGuard->unmark($hash); return $dataItem; }
/** * @since 2.2 * * @return QueryEngine */ public function newMasterQueryEngine() { $engineOptions = new EngineOptions(); $propertyHierarchyLookup = new PropertyHierarchyLookup($this->store, $this->applicationFactory->newCacheFactory()->newFixedInMemoryCache(500)); $propertyHierarchyLookup->setSubcategoryDepth($this->applicationFactory->getSettings()->get('smwgQSubcategoryDepth')); $propertyHierarchyLookup->setSubpropertyDepth($this->applicationFactory->getSettings()->get('smwgQSubpropertyDepth')); $circularReferenceGuard = new CircularReferenceGuard('sparql-query'); $circularReferenceGuard->setMaxRecursionDepth(2); $compoundConditionBuilder = new CompoundConditionBuilder($engineOptions); $compoundConditionBuilder->setCircularReferenceGuard($circularReferenceGuard); $compoundConditionBuilder->setPropertyHierarchyLookup($propertyHierarchyLookup); $queryEngine = new QueryEngine($this->store->getConnection('sparql'), $compoundConditionBuilder, new QueryResultFactory($this->store), $engineOptions); return $queryEngine; }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $this->query->setSubject(DIWIkiPage::newFromTitle($this->parserData->getTitle())); $queryHash = $this->query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); $format = $this->params['format']->getValue(); // FIXME Parser should be injected into the ResultPrinter // Enables specific formats to import its annotation data from // a recursive parse process in the result format // e.g. using ask query to search/set an invert property value if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) { $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); } if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->circularReferenceGuard->unmark($queryHash); $this->createQueryProfile($this->query, $format, $queryDuration); return $result; }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $queryHash = $this->query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); // FIXME Should be injected // A printer run its own isolated wgParser process therefore if the printer // or a template inclusion is used by a printer, possible extra annotations // need to be imported for further usage $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->circularReferenceGuard->unmark($queryHash); $this->createQueryProfile($this->query, $this->params['format']->getValue(), $queryDuration); return $result; }
private function doFetchResultsForRawParameters(array $rawParams) { $contextPage = $this->parserData->getSubject(); list($query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode, $contextPage); $query->setContextPage($contextPage); $queryHash = $query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); $format = $this->params['format']->getValue(); // FIXME Parser should be injected into the ResultPrinter // Enables specific formats to import its annotation data from // a recursive parse process in the result format // e.g. using ask query to search/set an invert property value if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) { $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); } $this->circularReferenceGuard->unmark($queryHash); // In case of an query error add a marker to the subject for discoverability // of a failed query, don't bail-out as we can have results and errors // at the same time if ($query->getErrors() !== array()) { $this->addProcessingError($query->getErrors()); } $this->createQueryProfile($query, $format); return $result; }
/** * @since 2.3 * * @return CachedValueLookupStore */ public function newCachedValueLookupStore() { $circularReferenceGuard = new CircularReferenceGuard('vl:store'); $circularReferenceGuard->setMaxRecursionDepth(2); $cacheFactory = ApplicationFactory::getInstance()->newCacheFactory(); $blobStore = new BlobStore('smw:vl:store', $cacheFactory->newMediaWikiCompositeCache($GLOBALS['smwgValueLookupCacheType'])); // If CACHE_NONE is selected, disable the usage $blobStore->setUsageState($GLOBALS['smwgValueLookupCacheType'] !== CACHE_NONE); $blobStore->setExpiryInSeconds($GLOBALS['smwgValueLookupCacheLifetime']); $blobStore->setNamespacePrefix($cacheFactory->getCachePrefix()); $cachedValueLookupStore = new CachedValueLookupStore($this->store, $blobStore); $cachedValueLookupStore->setValueLookupFeatures($GLOBALS['smwgValueLookupFeatures']); $cachedValueLookupStore->setCircularReferenceGuard($circularReferenceGuard); return $cachedValueLookupStore; }
/** * @since 2.5 * * @return EntityLookup */ public function newEntityLookup() { $settings = $this->applicationFactory->getSettings(); $directEntityLookup = new DirectEntityLookup($this->store); if ($settings->get('smwgValueLookupCacheType') === CACHE_NONE) { return $directEntityLookup; } $circularReferenceGuard = new CircularReferenceGuard('vl:store'); $circularReferenceGuard->setMaxRecursionDepth(2); $cacheFactory = $this->applicationFactory->newCacheFactory(); $blobStore = $cacheFactory->newBlobStore('smw:vl:store', $settings->get('smwgValueLookupCacheType'), $settings->get('smwgValueLookupCacheLifetime')); $cachedEntityLookup = new CachedEntityLookup($directEntityLookup, new RedirectTargetLookup($this->store, $circularReferenceGuard), $blobStore); $cachedEntityLookup->setCachedLookupFeatures($settings->get('smwgValueLookupFeatures')); return $cachedEntityLookup; }