SemanticMediaWiki / SemanticGlossary

Allows you define terms and abbreviations together with a definition.
https://www.mediawiki.org/wiki/Extension:Semantic_Glossary
Other
12 stars 11 forks source link

Remove `SemanticDataComparator` #11

Open mwjames opened 8 years ago

mwjames commented 8 years ago

SemanticDataComparator tries to detect whether a SG related property was exposed to an alteration and if so invalidated the cache. Executing SemanticDataComparator can be quite expensive and to avoid this, SMW 2.3 exposes CompositePropertyTableDiffIterator which contains the diff of inserted or deleted values.

The following change would do the same:

-       /**
-        * Invalidate on update
-        *
-        * @since 1.0
-        */
-       $this->handlers['SMWStore::updateDataBefore'] = function ( $store, $semanticData ) {
-           return \SG\Cache\CacheInvalidator::getInstance()->invalidateCacheOnStoreUpdate( $store, $semanticData );
+       $this->handlers['SMW::SQLStore::AfterDataUpdateComplete'] = function ( $store, $semanticData, $compositePropertyTableDiffIterator ) {
+
+           $hasChanged = false;
+
+           $mapCombinedIdListOfChangedEntities = array_flip(
+               $compositePropertyTableDiffIterator->getCombinedIdListOfChangedEntities()
+           );
+
+           foreach ( array( PropertyRegistry::SG_TERM, PropertyRegistry::SG_DEFINITION, PropertyRegistry::SG_LINK, PropertyRegistry::SG_STYLE ) as $property ) {
+               $id = $store->getObjectIds()->getSMWPropertyID(
+                   new \SMW\DIProperty( $property )
+               );
+
+               if ( isset( $mapCombinedIdListOfChangedEntities[$id] ) ) {
+                   $hasChanged = true;
+                   break;
+               }
+           }
+
+           if ( $hasChanged ) {
+               \SG\Cache\CacheInvalidator::getInstance()->invalidateCacheOnPageDelete(
+                   $store,
+                   $semanticData->getSubject()
+               );
+
+               wfDebugLog( 'smw', 'Run SG CacheInvalidator on ' . $semanticData->getSubject()->getHash() );
+           }
+
+           return true;
        };
mwjames commented 8 years ago

@s7eph4n Above would require SMW 2.3.

s7eph4n commented 8 years ago

Could you make this a pull request? I have no problems with requiring SMW 2.3. Might as well go all the way while I am at it.