Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SemanticDataComparator #11

Open
mwjames opened this issue Mar 6, 2016 · 2 comments
Open

Remove SemanticDataComparator #11

mwjames opened this issue Mar 6, 2016 · 2 comments

Comments

@mwjames
Copy link
Contributor

mwjames commented Mar 6, 2016

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
Copy link
Contributor Author

mwjames commented Mar 6, 2016

@s7eph4n Above would require SMW 2.3.

@s7eph4n
Copy link
Contributor

s7eph4n commented Mar 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants