public function testResetCache()
 {
     $subject = new DIWikiPage('Foo', NS_MAIN);
     $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('exporter.dataitem.resource.encoder');
     $poolCache->save($subject->getHash(), true);
     $poolCache->save($subject->getHash() . DataItemToExpResourceEncoder::AUX_MARKER, true);
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $instance = new DataItemToExpResourceEncoder($store);
     $instance->resetCacheFor($subject);
     $this->assertFalse($poolCache->contains($subject->getHash()));
 }
Example #2
0
 public function testGetRedirectTargetFromInMemoryCache()
 {
     $inMemoryPoolCache = InMemoryPoolCache::getInstance();
     $instance = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $wikipage = new DIWikiPage('Foo', NS_MAIN);
     $expected = new DIWikiPage('Bar', NS_MAIN);
     $inMemoryPoolCache->getPoolCacheFor('store.redirectTarget.lookup')->save($wikipage->getHash(), $expected);
     $this->assertEquals($expected, $instance->getRedirectTarget($wikipage));
     $inMemoryPoolCache->resetPoolCacheFor('store.redirectTarget.lookup');
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $markForAuxiliaryUsage
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $markForAuxiliaryUsage = false)
 {
     $modifier = $markForAuxiliaryUsage ? self::AUX_MARKER : '';
     $hash = $this->cachePrefix . $diWikiPage->getHash() . $modifier;
     // If a persistent cache is injected use the ExpElement serializer because
     // not all cache layers support object de/serialization
     // ExpElement::newFromSerialization
     if ($this->cache->contains($hash)) {
         return $this->cache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $importDataItem = $this->tryToFindImportDataItem($diWikiPage, $modifier);
     if ($importDataItem instanceof DataItem) {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForImportDataItem($importDataItem);
     } else {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForDiWikiPage($diWikiPage, $modifier);
     }
     $resource = new ExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
     $this->cache->save($hash, $resource);
     return $resource;
 }
 /**
  * Helper method to make sure there is a cache entry for the data about
  * the given subject with the given ID.
  *
  * @todo The management of this cache should be revisited.
  *
  * @since 1.8
  *
  * @param int $subjectId
  * @param DIWikiPage $subject
  */
 private function initSemanticDataCache($subjectId, DIWikiPage $subject)
 {
     // *** Prepare the cache ***//
     if (!array_key_exists($subjectId, $this->store->m_semdata)) {
         // new cache entry
         $this->store->m_semdata[$subjectId] = new SMWSql3StubSemanticData($subject, $this->store, false);
         $this->store->m_sdstate[$subjectId] = array();
     }
     // Issue #622
     // If a redirect was cached preceding this request and points to the same
     // subject id ensure that in all cases the requested subject matches with
     // the selected DB id
     if ($this->store->m_semdata[$subjectId]->getSubject()->getHash() !== $subject->getHash()) {
         $this->store->m_semdata[$subjectId] = new SMWSql3StubSemanticData($subject, $this->store, false);
         $this->store->m_sdstate[$subjectId] = array();
     }
     if (count($this->store->m_semdata) > 20 && self::$in_getSemanticData == 1) {
         // prevent memory leak;
         // It is not so easy to find the sweet spot between cache size and performance gains (both memory and time),
         // The value of 20 was chosen by profiling runtimes for large inline queries and heavily annotated pages.
         // However, things might have changed in the meantime ...
         $this->store->m_semdata = array($subjectId => $this->store->m_semdata[$subjectId]);
         $this->store->m_sdstate = array($subjectId => $this->store->m_sdstate[$subjectId]);
     }
 }
 private function doMatchSubcategory(&$subjects, DIWikiPage $category)
 {
     $hash = $category->getHash();
     $subcategories = array();
     // #1713
     // Safeguard against a possible category (or redirect thereof) to point
     // to itself by relying on tracking the hash of already inserted objects
     if (!isset($subjects[$hash])) {
         $subcategories = $this->propertyHierarchyLookup->findSubcategoryListFor($category);
     }
     foreach ($subcategories as $subcategory) {
         $subjects[$subcategory->getHash()] = $subcategory;
         if ($this->propertyHierarchyLookup->hasSubcategoryFor($subcategory)) {
             $this->doMatchSubcategory($subjects, $subcategory);
         }
     }
 }
 /**
  * This method is called from the `SMW::SQLStore::AfterDataUpdateComplete` hook and
  * removes outdated query ID's from the table if the diff contains a `delete`
  * entry for the _ask table.
  *
  * @since 2.3
  *
  * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator
  */
 public function pruneOutdatedTargetLinks(DIWikiPage $subject, CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator)
 {
     if (!$this->isEnabled()) {
         return null;
     }
     $start = microtime(true);
     $tableName = $this->store->getPropertyTableInfoFetcher()->findTableIdForProperty(new DIProperty('_ASK'));
     $tableChangeOps = $compositePropertyTableDiffIterator->getTableChangeOps($tableName);
     // Remove any dependency for queries that are no longer used
     foreach ($tableChangeOps as $tableChangeOp) {
         if (!$tableChangeOp->hasChangeOp('delete')) {
             continue;
         }
         $deleteIdList = array();
         foreach ($tableChangeOp->getFieldChangeOps('delete') as $fieldChangeOp) {
             $deleteIdList[] = $fieldChangeOp->get('o_id');
         }
         $this->dependencyLinksTableUpdater->deleteDependenciesFromList($deleteIdList);
     }
     wfDebugLog('smw', __METHOD__ . ' finished on ' . $subject->getHash() . ' with procTime (sec): ' . round(microtime(true) - $start, 7));
     return true;
 }
 /**
  * @since 2.4
  *
  * @param DIWikiPage $subject, $subobjectName
  * @param string $subobjectName
  */
 public function createId(DIWikiPage $subject, $subobjectName = '')
 {
     $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false);
     wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " {$subobjectName}");
     return $id;
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $useAuxiliaryModifier
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $useAuxiliaryModifier = false)
 {
     $modifier = $useAuxiliaryModifier ? self::AUX_MARKER : '';
     $hash = $diWikiPage->getHash() . $modifier;
     $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('exporter.dataitem.resource.encoder');
     if ($poolCache->contains($hash)) {
         return $poolCache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $importDataItem = $this->tryToFindImportDataItem($diWikiPage, $modifier);
     if ($importDataItem instanceof DataItem) {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForImportDataItem($importDataItem);
     } else {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForDiWikiPage($diWikiPage, $modifier);
     }
     $resource = new ExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
     $poolCache->save($hash, $resource);
     return $resource;
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $useAuxiliaryModifier
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $useAuxiliaryModifier = false)
 {
     $modifier = $useAuxiliaryModifier ? self::AUX_MARKER : '';
     $hash = $diWikiPage->getHash() . $modifier;
     $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('exporter.dataitem.resource.encoder');
     if ($poolCache->contains($hash)) {
         return $poolCache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $resource = $this->newExpNsResource($diWikiPage, $modifier);
     $poolCache->save($hash, $resource);
     return $resource;
 }
 /**
  * @since 2.3
  *
  * @param DIWikiPage $subject, $subobjectName
  * @param string $subobjectName
  */
 public function tryToMakeIdForSubject(DIWikiPage $subject, $subobjectName = '')
 {
     if ($subject->getNamespace() !== NS_CATEGORY && $subject->getNamespace() !== SMW_NS_PROPERTY) {
         return 0;
     }
     $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false);
     wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " \n");
     return $id;
 }
 /**
  * @since 2.5
  *
  * @return string
  */
 public function getHash()
 {
     return md5($this->hash . ($this->subject !== null ? $this->subject->getHash() : ''));
 }