Skip to content

Remove SemanticDataComparator #11

@mwjames

Description

@mwjames

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;
        };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions