From b88ec5afa509bed779d13c495f24bffd766c4507 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 1 Nov 2023 12:26:31 +0200 Subject: [PATCH 01/13] feat: decrease query count by cacheing some RDF property fields --- config/default/RedisCache.conf.php | 11 + core/kernel/classes/class.Property.php | 180 +++++++---- core/kernel/classes/class.Resource.php | 3 +- core/kernel/persistence/Cache.php | 28 ++ .../persistence/smoothsql/class.Property.php | 18 +- .../smoothsql/class.SmoothModel.php | 14 +- .../persistence/starsql/class.Property.php | 16 +- .../persistence/starsql/class.StarModel.php | 5 +- .../unit/core/kernel/classes/PropertyTest.php | 305 ++++++++++++++++++ 9 files changed, 492 insertions(+), 88 deletions(-) create mode 100644 config/default/RedisCache.conf.php create mode 100755 core/kernel/persistence/Cache.php create mode 100644 test/unit/core/kernel/classes/PropertyTest.php diff --git a/config/default/RedisCache.conf.php b/config/default/RedisCache.conf.php new file mode 100644 index 000000000..4790c1c10 --- /dev/null +++ b/config/default/RedisCache.conf.php @@ -0,0 +1,11 @@ + 'redis' +]); diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index 096629907..bf8ad2b2c 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -31,6 +31,7 @@ use oat\generis\model\GenerisRdf; use oat\generis\model\OntologyRdfs; use oat\generis\model\resource\DependsOnPropertyCollection; +use oat\generis\model\kernel\persistence\Cache; /** * uriProperty must be a valid property otherwis return false, add this as a @@ -86,23 +87,6 @@ class core_kernel_classes_Property extends core_kernel_classes_Resource */ public $widget = false; - /** - * Short description of attribute lgDependent - * - * @access public - * @var boolean - */ - public $lgDependent = false; - - - /** - * Short description of attribute multiple - * - * @access public - * @var boolean - */ - public $multiple = false; - /** @var DependsOnPropertyCollection */ private $dependsOnPropertyCollection; @@ -115,7 +99,6 @@ private function getImplementation() return $this->getModel()->getRdfsInterface()->getPropertyImplementation(); } - /** * constructor * @@ -128,9 +111,6 @@ private function getImplementation() public function __construct($uri, $debug = '') { parent::__construct($uri, $debug); - - $this->lgDependent = null; - $this->multiple = null; } /** @@ -237,6 +217,7 @@ public function getRange() $this->range = $returnValue; } $returnValue = $this->range; + return $returnValue; } @@ -248,14 +229,13 @@ public function getRange() * @param Class class * @return boolean */ - public function setRange(core_kernel_classes_Class $class) + public function setRange(core_kernel_classes_Class $class): bool { - $returnValue = (bool) false; $returnValue = $this->getImplementation()->setRange($this, $class); if ($returnValue) { $this->range = $class; } - return (bool) $returnValue; + return (bool)$returnValue; } public function getAlias(): ?string @@ -326,12 +306,19 @@ public function getWidget() * @author Cédric Alfonsi, * @return boolean */ - public function isLgDependent() + public function isLgDependent(): bool { - if (is_null($this->lgDependent)) { - $this->lgDependent = $this->getImplementation()->isLgDependent($this); + if ($this->supportCache() && $this->getModel()->getCache()->has($this->generateIsLgDependentKey($this->getUri()))) { + return (bool)$this->getModel()->getCache()->get($this->generateIsLgDependentKey($this->getUri())); + } + + $isLgDependent = $this->getImplementation()->isLgDependent($this); + + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsLgDependentKey($this->getUri()), $isLgDependent); } - return (bool) $this->lgDependent; + + return $isLgDependent; } /** @@ -339,13 +326,15 @@ public function isLgDependent() * * @access public * @author Cédric Alfonsi, - * @param boolean isLgDependent * @return mixed */ - public function setLgDependent($isLgDependent) + public function setLgDependent($isLgDependent): void { $this->getImplementation()->setLgDependent($this, $isLgDependent); - $this->lgDependent = $isLgDependent; + + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsLgDependentKey($this->getUri()), $isLgDependent); + } } /** @@ -355,24 +344,26 @@ public function setLgDependent($isLgDependent) * @author Cédric Alfonsi, * @return boolean */ - public function isMultiple() + public function isMultiple(): bool { - $returnValue = (bool) false; + if ($this->supportCache() && $this->getModel()->getCache()->has($this->generateIsMultipleKey($this->getUri()))) { + return (bool)$this->getModel()->getCache()->get($this->generateIsMultipleKey($this->getUri())); + } - if (is_null($this->multiple)) { - $multipleProperty = $this->getProperty(GenerisRdf::PROPERTY_MULTIPLE); - $multiple = $this->getOnePropertyValue($multipleProperty); + $multipleProperty = $this->getProperty(GenerisRdf::PROPERTY_MULTIPLE); + $multiple = $this->getOnePropertyValue($multipleProperty); - if (is_null($multiple)) { - $returnValue = false; - } else { - $returnValue = ($multiple->getUri() == GenerisRdf::GENERIS_TRUE); - } - $this->multiple = $returnValue; + if (is_null($multiple)) { + $returnValue = false; + } else { + $returnValue = ($multiple->getUri() == GenerisRdf::GENERIS_TRUE); } - $returnValue = $this->multiple; - return (bool) $returnValue; + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsMultipleKey($this->getUri()), $returnValue); + } + + return $returnValue; } /** @@ -381,14 +372,15 @@ public function isMultiple() * * @access public * @author Cédric Alfonsi, - * @param boolean isMultiple * @return mixed */ - public function setMultiple($isMultiple) + public function setMultiple($isMultiple): void { - $this->getImplementation()->setMultiple($this, $isMultiple); - $this->multiple = $isMultiple; + + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsMultipleKey($this->getUri()), $isMultiple); + } } /** @@ -398,17 +390,15 @@ public function setMultiple($isMultiple) */ public function isRelationship(): bool { - if (in_array($this->getUri(), self::RELATIONSHIP_PROPERTIES)) { - return true; - } + $model = $this->getModel(); - if ($this->getUri() === OntologyRdf::RDF_VALUE) { - return false; + if ($this->supportCache() && $model->getCache()->has($this->generateIsRelationshipKey($this->getUri()))) { + return (bool)$model->getCache()->get($this->generateIsRelationshipKey($this->getUri())); } $range = $this->getRange(); - return $range + $isRelationship = $range && !in_array( $range->getUri(), [ @@ -417,6 +407,12 @@ public function isRelationship(): bool ], true ); + + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsRelationshipKey($this->getUri()), $isRelationship); + } + + return $isRelationship; } /** @@ -427,10 +423,82 @@ public function isRelationship(): bool * @param boolean deleteReference * @return boolean */ - public function delete($deleteReference = false) + public function delete($deleteReference = false): bool { - $returnValue = (bool) false; $returnValue = $this->getImplementation()->delete($this, $deleteReference); + + $this->clearCachedValues($this->getUri()); + return (bool) $returnValue; } + /** + * Clear property cached data + * + * @param string $uri + */ + protected function clearCachedValues(string $uri): void + { + if (!$this->supportCache()) { + return; + } + + /** @var \oat\oatbox\cache\SimpleCache $cache */ + $cache = $this->getModel()->getCache(); + $isRelationshipKey = $this->generateIsRelationshipKey($uri); + $isMultipleKey = $this->generateIsMultipleKey($uri); + $isLgDependentKey = $this->generateIsLgDependentKey($uri); + + if ($cache->has($isRelationshipKey)) { + $cache->delete($isRelationshipKey); + } + + if ($cache->has($isMultipleKey)) { + $cache->delete($isMultipleKey); + } + + if ($cache->has($isLgDependentKey)) { + $cache->delete($isLgDependentKey); + } + } + + /** + * Generate cache key for relationship data + * + * @param string $uri + * @return string + */ + protected function generateIsRelationshipKey(string $uri): string + { + return sprintf('PropIsRelationship_%s', $uri); + } + + /** + * Generate cache key for lg dependent data + * + * @param string $uri + * @return string + */ + protected function generateIsLgDependentKey(string $uri): string + { + return sprintf('PropIsLgDependent_%s', $uri); + } + + /** + * Generate cache key for multiple data + * + * @param string $uri + * @return string + */ + protected function generateIsMultipleKey(string $uri): string + { + return sprintf('PropIsMultiple_%s', $uri); + } + + /** + * @return bool + */ + protected function supportCache(): bool + { + return $this->getModel() instanceof Cache; + } } diff --git a/core/kernel/classes/class.Resource.php b/core/kernel/classes/class.Resource.php index 148e24b25..3d041df3a 100644 --- a/core/kernel/classes/class.Resource.php +++ b/core/kernel/classes/class.Resource.php @@ -302,9 +302,8 @@ public function setComment($comment) */ public function getPropertyValues(core_kernel_classes_Property $property, $options = []) { - $returnValue = []; $returnValue = $this->getImplementation()->getPropertyValues($this, $property, $options); - return (array) $returnValue; + return $returnValue; } /** diff --git a/core/kernel/persistence/Cache.php b/core/kernel/persistence/Cache.php new file mode 100755 index 000000000..d712e5509 --- /dev/null +++ b/core/kernel/persistence/Cache.php @@ -0,0 +1,28 @@ +getModel()->getCache()->get($resource->getUri()); - if (is_null($lgDependent)) { - $lgDependentProperty = $this->getModel()->getProperty(GenerisRdf::PROPERTY_IS_LG_DEPENDENT); - $lgDependentResource = $resource->getOnePropertyValue($lgDependentProperty); - $lgDependent = !is_null($lgDependentResource) - && $lgDependentResource instanceof \core_kernel_classes_Resource - && $lgDependentResource->getUri() == GenerisRdf::GENERIS_TRUE; - $this->getModel()->getCache()->set($resource->getUri(), $lgDependent); - } + $lgDependentProperty = $this->getModel()->getProperty(GenerisRdf::PROPERTY_IS_LG_DEPENDENT); + $lgDependentResource = $resource->getOnePropertyValue($lgDependentProperty); + $lgDependent = !is_null($lgDependentResource) + && $lgDependentResource instanceof \core_kernel_classes_Resource + && $lgDependentResource->getUri() == GenerisRdf::GENERIS_TRUE; + return (bool) $lgDependent; } @@ -174,7 +171,6 @@ public function setDependsOnProperty( */ public function setMultiple(core_kernel_classes_Resource $resource, $isMultiple) { - $multipleProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_MULTIPLE); $value = ((bool)$isMultiple) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE ; $this->removePropertyValues($resource, $multipleProperty); @@ -192,7 +188,6 @@ public function setMultiple(core_kernel_classes_Resource $resource, $isMultiple) */ public function setLgDependent(core_kernel_classes_Resource $resource, $isLgDependent) { - $lgDependentProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_IS_LG_DEPENDENT, __METHOD__); $value = ((bool)$isLgDependent) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE ; $this->removePropertyValues($resource, $lgDependentProperty); @@ -208,7 +203,6 @@ public function setLgDependent(core_kernel_classes_Resource $resource, $isLgDepe */ public static function singleton() { - $returnValue = null; if (core_kernel_persistence_smoothsql_Property::$instance == null) { core_kernel_persistence_smoothsql_Property::$instance = new core_kernel_persistence_smoothsql_Property(); } diff --git a/core/kernel/persistence/smoothsql/class.SmoothModel.php b/core/kernel/persistence/smoothsql/class.SmoothModel.php index cef6f2d9c..da31ade46 100755 --- a/core/kernel/persistence/smoothsql/class.SmoothModel.php +++ b/core/kernel/persistence/smoothsql/class.SmoothModel.php @@ -20,13 +20,14 @@ */ use oat\generis\model\data\ModelManager; -use oat\oatbox\service\ConfigurableService; -use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\generis\model\data\Ontology; -use oat\generis\persistence\sql\SchemaProviderInterface; -use oat\generis\persistence\sql\SchemaCollection; +use oat\generis\model\kernel\persistence\Cache; use oat\generis\model\kernel\persistence\smoothsql\install\SmoothRdsModel; +use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; +use oat\generis\persistence\sql\SchemaCollection; +use oat\generis\persistence\sql\SchemaProviderInterface; use oat\oatbox\cache\SimpleCache; +use oat\oatbox\service\ConfigurableService; /** * transitory model for the smooth sql implementation @@ -36,7 +37,8 @@ */ class core_kernel_persistence_smoothsql_SmoothModel extends ConfigurableService implements Ontology, - SchemaProviderInterface + SchemaProviderInterface, + Cache { public const OPTION_PERSISTENCE = 'persistence'; public const OPTION_READABLE_MODELS = 'readable'; @@ -104,7 +106,7 @@ public function getPersistence() public function getCache(): SimpleCache { - return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); + return $this->getServiceLocator()->get('generis/RedisCache'); } /** diff --git a/core/kernel/persistence/starsql/class.Property.php b/core/kernel/persistence/starsql/class.Property.php index 1ddd2c626..4e0427c81 100644 --- a/core/kernel/persistence/starsql/class.Property.php +++ b/core/kernel/persistence/starsql/class.Property.php @@ -33,15 +33,12 @@ class core_kernel_persistence_starsql_Property extends core_kernel_persistence_s public function isLgDependent(core_kernel_classes_Resource $resource): bool { - $lgDependent = $this->getModel()->getCache()->get($resource->getUri()); - if (is_null($lgDependent)) { - $lgDependentProperty = $this->getModel()->getProperty(GenerisRdf::PROPERTY_IS_LG_DEPENDENT); - $lgDependentResource = $resource->getOnePropertyValue($lgDependentProperty); - $lgDependent = !is_null($lgDependentResource) - && $lgDependentResource instanceof \core_kernel_classes_Resource - && $lgDependentResource->getUri() == GenerisRdf::GENERIS_TRUE; - $this->getModel()->getCache()->set($resource->getUri(), $lgDependent); - } + $lgDependentProperty = $this->getModel()->getProperty(GenerisRdf::PROPERTY_IS_LG_DEPENDENT); + $lgDependentResource = $resource->getOnePropertyValue($lgDependentProperty); + $lgDependent = !is_null($lgDependentResource) + && $lgDependentResource instanceof \core_kernel_classes_Resource + && $lgDependentResource->getUri() == GenerisRdf::GENERIS_TRUE; + return (bool) $lgDependent; } @@ -105,7 +102,6 @@ public function setMultiple(core_kernel_classes_Resource $resource, $isMultiple) public function setLgDependent(core_kernel_classes_Resource $resource, $isLgDependent) { - $lgDependentProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_IS_LG_DEPENDENT, __METHOD__); $value = ((bool)$isLgDependent) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE ; $this->setPropertyValue($resource, $lgDependentProperty, $value); diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index 6ba42395c..791250751 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -20,11 +20,12 @@ use oat\generis\model\data\ModelManager; use oat\generis\model\data\Ontology; +use oat\generis\model\kernel\persistence\Cache; use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\oatbox\cache\SimpleCache; use oat\oatbox\service\ConfigurableService; -class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology +class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology, Cache { public const OPTION_PERSISTENCE = 'persistence'; public const OPTION_READABLE_MODELS = 'readable'; @@ -89,7 +90,7 @@ public function getPersistence(): common_persistence_GraphPersistence public function getCache(): SimpleCache { - return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); + return $this->getServiceLocator()->get('generis/RedisCache'); } /** diff --git a/test/unit/core/kernel/classes/PropertyTest.php b/test/unit/core/kernel/classes/PropertyTest.php new file mode 100644 index 000000000..28c04ded6 --- /dev/null +++ b/test/unit/core/kernel/classes/PropertyTest.php @@ -0,0 +1,305 @@ +model = $this->createMock(core_kernel_persistence_starsql_StarModel::class); + $this->rdfs = $this->createMock(RdfsInterface::class); + $this->persistenceProperty = $this->createMock(core_kernel_persistence_PropertyInterface::class); + $this->cache = $this->createMock(SimpleCache::class); + + $this->model + ->method('getRdfsInterface') + ->willReturn($this->rdfs); + $this->rdfs + ->method('getPropertyImplementation') + ->willReturn($this->persistenceProperty); + + $this->model + ->method('getCache') + ->willReturn($this->cache); + + $this->property = $this->createPartialMock( + core_kernel_classes_Property::class, + ['getRange', 'getProperty', 'getOnePropertyValue'] + ); + $this->property->__construct('uri'); + $this->property->setModel($this->model); + } + + public function testIsRelationshipFalseWithoutCache(): void + { + $this->property + ->expects(self::once()) + ->method('getRange') + ->willReturn(new core_kernel_classes_Property(OntologyRdfs::RDFS_LITERAL)); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsRelationship_uri') + ->willReturn(false); + $this->cache + ->expects(self::never()) + ->method('get'); + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsRelationship_uri', false); + + $result = $this->property->isRelationship(); + + $this->assertFalse($result); + } + + public function testIsRelationshipTrueWithoutCache(): void + { + $this->property + ->expects(self::once()) + ->method('getRange') + ->willReturn(new core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL)); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsRelationship_uri') + ->willReturn(false); + $this->cache + ->expects(self::never()) + ->method('get'); + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsRelationship_uri', true); + + $result = $this->property->isRelationship(); + + $this->assertTrue($result); + } + + public function testIsRelationshipTrueWithCache(): void + { + $this->property + ->expects(self::never()) + ->method('getRange'); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsRelationship_uri') + ->willReturn(true); + $this->cache + ->expects(self::once()) + ->method('get') + ->with('PropIsRelationship_uri') + ->willReturn(true); + $this->cache + ->expects(self::never()) + ->method('set'); + + $result = $this->property->isRelationship(); + + $this->assertTrue($result); + } + + public function testIsLgDependentFalseWithoutCache(): void + { + $this->persistenceProperty + ->expects(self::once()) + ->method('isLgDependent') + ->willReturn(false); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsLgDependent_uri') + ->willReturn(false); + $this->cache + ->expects(self::never()) + ->method('get'); + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsLgDependent_uri', false); + + $result = $this->property->isLgDependent(); + + $this->assertFalse($result); + } + + public function testIsLgDependentTrueWithCache(): void + { + $this->persistenceProperty + ->expects(self::never()) + ->method('isLgDependent'); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsLgDependent_uri') + ->willReturn(true); + $this->cache + ->expects(self::once()) + ->method('get') + ->with('PropIsLgDependent_uri') + ->willReturn(true); + $this->cache + ->expects(self::never()) + ->method('set'); + + $result = $this->property->isLgDependent(); + + $this->assertTrue($result); + } + + public function testSetLgDependent(): void + { + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsLgDependent_uri', true); + + $this->property->setLgDependent(true); + } + + public function testIsMultipleTrueWithoutCache(): void + { + $this->property + ->expects(self::once()) + ->method('getProperty') + ->willReturn(new core_kernel_classes_Property('test')); + $this->property + ->expects(self::once()) + ->method('getOnePropertyValue') + ->willReturn(new core_kernel_classes_Property(GenerisRdf::GENERIS_TRUE)); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsMultiple_uri') + ->willReturn(false); + $this->cache + ->expects(self::never()) + ->method('get'); + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsMultiple_uri', true); + + $result = $this->property->isMultiple(); + + $this->assertTrue($result); + } + + public function testIsMultipleFalseWithCache(): void + { + $this->property + ->expects(self::never()) + ->method('getProperty'); + $this->property + ->expects(self::never()) + ->method('getOnePropertyValue'); + + $this->cache + ->expects(self::once()) + ->method('has') + ->with('PropIsMultiple_uri') + ->willReturn(true); + $this->cache + ->expects(self::once()) + ->method('get') + ->with('PropIsMultiple_uri') + ->willReturn(false); + $this->cache + ->expects(self::never()) + ->method('set'); + + $result = $this->property->isMultiple(); + + $this->assertFalse($result); + } + + public function testSetMultiple(): void + { + $this->cache + ->expects(self::once()) + ->method('set') + ->with('PropIsMultiple_uri', true); + + $this->property->setMultiple(true); + } + + public function testOnDeleteWithCacheClear(): void + { + $this->cache + ->expects(self::exactly(3)) + ->method('has') + ->withConsecutive(['PropIsRelationship_uri'], ['PropIsMultiple_uri'], ['PropIsLgDependent_uri']) + ->willReturnOnConsecutiveCalls(true, true, true); + $this->cache + ->expects(self::exactly(3)) + ->method('delete') + ->withConsecutive(['PropIsRelationship_uri'], ['PropIsMultiple_uri'], ['PropIsLgDependent_uri']); + + $this->property->delete(); + } + + public function testOnDeleteWithoutCacheClear(): void + { + $this->cache + ->expects(self::exactly(3)) + ->method('has') + ->withConsecutive(['PropIsRelationship_uri'], ['PropIsMultiple_uri'], ['PropIsLgDependent_uri']) + ->willReturnOnConsecutiveCalls(false, false, false); + $this->cache + ->expects(self::never()) + ->method('delete'); + + $this->property->delete(); + } +} From db207e0a90a7b1061569d155ce5fa5f3233fecd1 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Thu, 2 Nov 2023 10:23:12 +0200 Subject: [PATCH 02/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 35 ++++++++++++++++++++------ helpers/class.PropertyCache.php | 26 +++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100755 helpers/class.PropertyCache.php diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index bf8ad2b2c..eb3d1533f 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -390,6 +390,14 @@ public function setMultiple($isMultiple): void */ public function isRelationship(): bool { + if (in_array($this->getUri(), self::RELATIONSHIP_PROPERTIES)) { + return true; + } + + if ($this->getUri() === OntologyRdf::RDF_VALUE) { + return false; + } + $model = $this->getModel(); if ($this->supportCache() && $model->getCache()->has($this->generateIsRelationshipKey($this->getUri()))) { @@ -427,16 +435,15 @@ public function delete($deleteReference = false): bool { $returnValue = $this->getImplementation()->delete($this, $deleteReference); - $this->clearCachedValues($this->getUri()); + $this->clearCachedValues(); return (bool) $returnValue; } + /** * Clear property cached data - * - * @param string $uri */ - protected function clearCachedValues(string $uri): void + public function clearCachedValues(): void { if (!$this->supportCache()) { return; @@ -444,9 +451,9 @@ protected function clearCachedValues(string $uri): void /** @var \oat\oatbox\cache\SimpleCache $cache */ $cache = $this->getModel()->getCache(); - $isRelationshipKey = $this->generateIsRelationshipKey($uri); - $isMultipleKey = $this->generateIsMultipleKey($uri); - $isLgDependentKey = $this->generateIsLgDependentKey($uri); + $isRelationshipKey = $this->generateIsRelationshipKey($this->getUri()); + $isMultipleKey = $this->generateIsMultipleKey($this->getUri()); + $isLgDependentKey = $this->generateIsLgDependentKey($this->getUri()); if ($cache->has($isRelationshipKey)) { $cache->delete($isRelationshipKey); @@ -461,6 +468,20 @@ protected function clearCachedValues(string $uri): void } } + /** + * Warmup property cached data + */ + public function warmupCachedValues(): void + { + if (!$this->supportCache()) { + return; + } + + $this->isRelationship(); + $this->isMultiple(); + $this->isLgDependent(); + } + /** * Generate cache key for relationship data * diff --git a/helpers/class.PropertyCache.php b/helpers/class.PropertyCache.php new file mode 100755 index 000000000..284282ac2 --- /dev/null +++ b/helpers/class.PropertyCache.php @@ -0,0 +1,26 @@ +predicate); + $property->clearCachedValues(); + } + } + + /** + * Warmup property cached data + */ + public static function warmupCachedValues(Iterator $triples): void + { + foreach ($triples as $triple) { + $property = new \core_kernel_classes_Property($triple->predicate); + $property->warmupCachedValues(); + } + } +} From 7d804f9fe6f1342a7c317de568f5c26afa93f282 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Thu, 2 Nov 2023 11:06:17 +0200 Subject: [PATCH 03/13] feat: decrease query count by cacheing some RDF property fields --- helpers/class.PropertyCache.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/helpers/class.PropertyCache.php b/helpers/class.PropertyCache.php index 284282ac2..919bfd064 100755 --- a/helpers/class.PropertyCache.php +++ b/helpers/class.PropertyCache.php @@ -5,22 +5,22 @@ class helpers_PropertyCache /** * Clear property cached data */ - public static function clearCachedValues(Iterator $triples): void + public static function clearCachedValuesByTriples(Iterator $triples): void { foreach ($triples as $triple) { - $property = new \core_kernel_classes_Property($triple->predicate); - $property->clearCachedValues(); + $classProperty = new \core_kernel_classes_Property($triple->predicate); + $classProperty->clearCachedValues(); } } /** * Warmup property cached data */ - public static function warmupCachedValues(Iterator $triples): void + public static function warmupCachedValuesByProperties(array $properties): void { - foreach ($triples as $triple) { - $property = new \core_kernel_classes_Property($triple->predicate); - $property->warmupCachedValues(); + foreach ($properties as $property) { + $classProperty = new \core_kernel_classes_Property($property); + $classProperty->warmupCachedValues(); } } } From 8b53713d8bd54f1deeda2a2e22516484900d7558 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 3 Nov 2023 15:12:57 +0200 Subject: [PATCH 04/13] feat: decrease query count by cacheing some RDF property fields --- test/OntologyMockTrait.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/OntologyMockTrait.php b/test/OntologyMockTrait.php index 0e6996f5c..9b3ec6c0c 100644 --- a/test/OntologyMockTrait.php +++ b/test/OntologyMockTrait.php @@ -101,6 +101,7 @@ private function setupOntology(Ontology $onto) Bin2HexUriProvider::OPTION_NAMESPACE => 'http://ontology.mock/bin2hex#' ]), SimpleCache::SERVICE_ID => new NoCache(), + 'generis/RedisCache' => new NoCache(), DriverConfigurationFeeder::SERVICE_ID => new DriverConfigurationFeeder(), EventAggregator::SERVICE_ID => $eventAggregator ]); @@ -129,7 +130,8 @@ protected function getPersistenceManagerWithSqlMock($sqlId) if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('sqlite not found, tests skipped.'); } - $pm = new PersistenceManager([ + + return new PersistenceManager([ PersistenceManager::OPTION_PERSISTENCES => [ $sqlId => [ 'driver' => 'dbal', @@ -139,7 +141,6 @@ protected function getPersistenceManagerWithSqlMock($sqlId) ] ] ]); - return $pm; } /** From dd0bd8296cfb8fc579375a7a4a3c35959dd576de Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 3 Nov 2023 15:24:36 +0200 Subject: [PATCH 05/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index eb3d1533f..17f863c5f 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -134,7 +134,6 @@ public function feed() */ public function getDomain() { - $returnValue = null; if (is_null($this->domain)) { $this->domain = new core_kernel_classes_ContainerCollection(new common_Object(__METHOD__)); $domainValues = $this->getPropertyValues($this->getProperty(OntologyRdfs::RDFS_DOMAIN)); @@ -142,10 +141,8 @@ public function getDomain() $this->domain->add($this->getClass($domainValue)); } } - $returnValue = $this->domain; - - return $returnValue; + return $this->domain; } public function getRelatedClass(): ?core_kernel_classes_Class @@ -211,14 +208,13 @@ public function getRange() $rangeProperty = $this->getProperty(OntologyRdfs::RDFS_RANGE); $rangeValues = $this->getPropertyValues($rangeProperty); - if (sizeOf($rangeValues) > 0) { + if (empty($rangeValues)) { $returnValue = $this->getClass($rangeValues[0]); } $this->range = $returnValue; } $returnValue = $this->range; - - return $returnValue; + return $this->range; } /** @@ -308,7 +304,9 @@ public function getWidget() */ public function isLgDependent(): bool { - if ($this->supportCache() && $this->getModel()->getCache()->has($this->generateIsLgDependentKey($this->getUri()))) { + if ($this->supportCache() && $this->getModel()->getCache()->has( + $this->generateIsLgDependentKey($this->getUri()) + )) { return (bool)$this->getModel()->getCache()->get($this->generateIsLgDependentKey($this->getUri())); } @@ -346,7 +344,9 @@ public function setLgDependent($isLgDependent): void */ public function isMultiple(): bool { - if ($this->supportCache() && $this->getModel()->getCache()->has($this->generateIsMultipleKey($this->getUri()))) { + if ($this->supportCache() && $this->getModel()->getCache()->has( + $this->generateIsMultipleKey($this->getUri()) + )) { return (bool)$this->getModel()->getCache()->get($this->generateIsMultipleKey($this->getUri())); } @@ -401,23 +401,23 @@ public function isRelationship(): bool $model = $this->getModel(); if ($this->supportCache() && $model->getCache()->has($this->generateIsRelationshipKey($this->getUri()))) { - return (bool)$model->getCache()->get($this->generateIsRelationshipKey($this->getUri())); - } - - $range = $this->getRange(); - - $isRelationship = $range - && !in_array( - $range->getUri(), - [ - OntologyRdfs::RDFS_LITERAL, - GenerisRdf::CLASS_GENERIS_FILE - ], - true - ); - - if ($this->supportCache()) { - $this->getModel()->getCache()->set($this->generateIsRelationshipKey($this->getUri()), $isRelationship); + $isRelationship = (bool)$model->getCache()->get($this->generateIsRelationshipKey($this->getUri())); + } else { + $range = $this->getRange(); + + $isRelationship = $range + && !in_array( + $range->getUri(), + [ + OntologyRdfs::RDFS_LITERAL, + GenerisRdf::CLASS_GENERIS_FILE + ], + true + ); + + if ($this->supportCache()) { + $this->getModel()->getCache()->set($this->generateIsRelationshipKey($this->getUri()), $isRelationship); + } } return $isRelationship; From 6192666884c9c78938d485a58ed5ae5a1588d4fd Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 3 Nov 2023 15:27:48 +0200 Subject: [PATCH 06/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index 17f863c5f..647dd98c2 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -214,7 +214,7 @@ public function getRange() $this->range = $returnValue; } $returnValue = $this->range; - return $this->range; + return $returnValue; } /** From b3249be9e35e04c56a74427412d5c0f772386327 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 3 Nov 2023 16:14:01 +0200 Subject: [PATCH 07/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index 647dd98c2..b832dc8dc 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -304,9 +304,10 @@ public function getWidget() */ public function isLgDependent(): bool { - if ($this->supportCache() && $this->getModel()->getCache()->has( - $this->generateIsLgDependentKey($this->getUri()) - )) { + if ( + $this->supportCache() + && $this->getModel()->getCache()->has($this->generateIsLgDependentKey($this->getUri())) + ) { return (bool)$this->getModel()->getCache()->get($this->generateIsLgDependentKey($this->getUri())); } @@ -344,9 +345,10 @@ public function setLgDependent($isLgDependent): void */ public function isMultiple(): bool { - if ($this->supportCache() && $this->getModel()->getCache()->has( - $this->generateIsMultipleKey($this->getUri()) - )) { + if ( + $this->supportCache() + && $this->getModel()->getCache()->has($this->generateIsMultipleKey($this->getUri())) + ) { return (bool)$this->getModel()->getCache()->get($this->generateIsMultipleKey($this->getUri())); } From 322cb4e31216d329fdf3bd0fc90933616045d522 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Thu, 9 Nov 2023 15:23:05 +0200 Subject: [PATCH 08/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 18 ------------------ ...ass.PropertyCache.php => PropertyCache.php} | 4 +++- 2 files changed, 3 insertions(+), 19 deletions(-) rename helpers/{class.PropertyCache.php => PropertyCache.php} (92%) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index b832dc8dc..c6b10ea8d 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -484,34 +484,16 @@ public function warmupCachedValues(): void $this->isLgDependent(); } - /** - * Generate cache key for relationship data - * - * @param string $uri - * @return string - */ protected function generateIsRelationshipKey(string $uri): string { return sprintf('PropIsRelationship_%s', $uri); } - /** - * Generate cache key for lg dependent data - * - * @param string $uri - * @return string - */ protected function generateIsLgDependentKey(string $uri): string { return sprintf('PropIsLgDependent_%s', $uri); } - /** - * Generate cache key for multiple data - * - * @param string $uri - * @return string - */ protected function generateIsMultipleKey(string $uri): string { return sprintf('PropIsMultiple_%s', $uri); diff --git a/helpers/class.PropertyCache.php b/helpers/PropertyCache.php similarity index 92% rename from helpers/class.PropertyCache.php rename to helpers/PropertyCache.php index 919bfd064..8ce3d5286 100755 --- a/helpers/class.PropertyCache.php +++ b/helpers/PropertyCache.php @@ -1,6 +1,8 @@ Date: Thu, 9 Nov 2023 17:49:52 +0200 Subject: [PATCH 09/13] feat: decrease query count by cacheing some RDF property fields --- config/default/PropertyCache.conf.php | 29 +++++++++++++++++++ config/default/RedisCache.conf.php | 11 ------- core/kernel/classes/class.Property.php | 2 +- .../smoothsql/class.SmoothModel.php | 2 +- .../persistence/starsql/class.StarModel.php | 2 +- 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 config/default/PropertyCache.conf.php delete mode 100644 config/default/RedisCache.conf.php diff --git a/config/default/PropertyCache.conf.php b/config/default/PropertyCache.conf.php new file mode 100644 index 000000000..e5ffef198 --- /dev/null +++ b/config/default/PropertyCache.conf.php @@ -0,0 +1,29 @@ +get(PersistenceManager::SERVICE_ID) + ->getPersistenceById('redis'); + + return new KeyValueCache([ + KeyValueCache::OPTION_PERSISTENCE => 'redis' + ]); + } catch (Exception $e) { + return new KeyValueCache([ + KeyValueCache::OPTION_PERSISTENCE => 'cache' + ]); + } + } +}; diff --git a/config/default/RedisCache.conf.php b/config/default/RedisCache.conf.php deleted file mode 100644 index 4790c1c10..000000000 --- a/config/default/RedisCache.conf.php +++ /dev/null @@ -1,11 +0,0 @@ - 'redis' -]); diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index c6b10ea8d..c07dc3491 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -208,7 +208,7 @@ public function getRange() $rangeProperty = $this->getProperty(OntologyRdfs::RDFS_RANGE); $rangeValues = $this->getPropertyValues($rangeProperty); - if (empty($rangeValues)) { + if (!empty($rangeValues)) { $returnValue = $this->getClass($rangeValues[0]); } $this->range = $returnValue; diff --git a/core/kernel/persistence/smoothsql/class.SmoothModel.php b/core/kernel/persistence/smoothsql/class.SmoothModel.php index da31ade46..57555f783 100755 --- a/core/kernel/persistence/smoothsql/class.SmoothModel.php +++ b/core/kernel/persistence/smoothsql/class.SmoothModel.php @@ -106,7 +106,7 @@ public function getPersistence() public function getCache(): SimpleCache { - return $this->getServiceLocator()->get('generis/RedisCache'); + return $this->getServiceLocator()->get('generis/PropertyCache'); } /** diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index 791250751..d023815a9 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -90,7 +90,7 @@ public function getPersistence(): common_persistence_GraphPersistence public function getCache(): SimpleCache { - return $this->getServiceLocator()->get('generis/RedisCache'); + return $this->getServiceLocator()->get('generis/PropertyCache'); } /** From e059037ab7c91cce65d95b99e5a82fcf61b29206 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 10 Nov 2023 12:59:34 +0200 Subject: [PATCH 10/13] feat: decrease query count by cacheing some RDF property fields --- test/OntologyMockTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OntologyMockTrait.php b/test/OntologyMockTrait.php index 9b3ec6c0c..c48c64011 100644 --- a/test/OntologyMockTrait.php +++ b/test/OntologyMockTrait.php @@ -101,7 +101,7 @@ private function setupOntology(Ontology $onto) Bin2HexUriProvider::OPTION_NAMESPACE => 'http://ontology.mock/bin2hex#' ]), SimpleCache::SERVICE_ID => new NoCache(), - 'generis/RedisCache' => new NoCache(), + 'generis/PropertyCache' => new NoCache(), DriverConfigurationFeeder::SERVICE_ID => new DriverConfigurationFeeder(), EventAggregator::SERVICE_ID => $eventAggregator ]); From ebc6a705659923a0475173bbe49f5f72e5ef5e9d Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Mon, 13 Nov 2023 11:48:26 +0200 Subject: [PATCH 11/13] feat: decrease query count by cacheing some RDF property fields --- common/oatbox/cache/KeyValueCache.php | 6 ++--- common/oatbox/cache/PropertyCache.php | 27 +++++++++++++++++++ config/default/PropertyCache.conf.php | 10 +++---- .../smoothsql/class.SmoothModel.php | 3 ++- .../persistence/starsql/class.StarModel.php | 3 ++- test/OntologyMockTrait.php | 3 ++- 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 common/oatbox/cache/PropertyCache.php diff --git a/common/oatbox/cache/KeyValueCache.php b/common/oatbox/cache/KeyValueCache.php index b7adf2245..c020cc4ac 100644 --- a/common/oatbox/cache/KeyValueCache.php +++ b/common/oatbox/cache/KeyValueCache.php @@ -21,12 +21,12 @@ namespace oat\oatbox\cache; -use oat\oatbox\service\ConfigurableService; -use common_persistence_KeyValuePersistence; -use oat\generis\persistence\PersistenceManager; use common_exception_NotImplemented; +use common_persistence_KeyValuePersistence; use DateInterval; use DateTimeImmutable; +use oat\generis\persistence\PersistenceManager; +use oat\oatbox\service\ConfigurableService; /** * Caches data in a key-value store diff --git a/common/oatbox/cache/PropertyCache.php b/common/oatbox/cache/PropertyCache.php new file mode 100644 index 000000000..a09e6c89b --- /dev/null +++ b/common/oatbox/cache/PropertyCache.php @@ -0,0 +1,27 @@ +get(PersistenceManager::SERVICE_ID) ->getPersistenceById('redis'); - return new KeyValueCache([ - KeyValueCache::OPTION_PERSISTENCE => 'redis' + return new PropertyCache([ + PropertyCache::OPTION_PERSISTENCE => 'redis' ]); } catch (Exception $e) { - return new KeyValueCache([ - KeyValueCache::OPTION_PERSISTENCE => 'cache' + return new PropertyCache([ + PropertyCache::OPTION_PERSISTENCE => 'cache' ]); } } diff --git a/core/kernel/persistence/smoothsql/class.SmoothModel.php b/core/kernel/persistence/smoothsql/class.SmoothModel.php index 57555f783..44a75b15e 100755 --- a/core/kernel/persistence/smoothsql/class.SmoothModel.php +++ b/core/kernel/persistence/smoothsql/class.SmoothModel.php @@ -26,6 +26,7 @@ use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\generis\persistence\sql\SchemaCollection; use oat\generis\persistence\sql\SchemaProviderInterface; +use oat\oatbox\cache\PropertyCache; use oat\oatbox\cache\SimpleCache; use oat\oatbox\service\ConfigurableService; @@ -106,7 +107,7 @@ public function getPersistence() public function getCache(): SimpleCache { - return $this->getServiceLocator()->get('generis/PropertyCache'); + return $this->getServiceLocator()->get(PropertyCache::SERVICE_ID); } /** diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index d023815a9..d9d146d23 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -22,6 +22,7 @@ use oat\generis\model\data\Ontology; use oat\generis\model\kernel\persistence\Cache; use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; +use oat\oatbox\cache\PropertyCache; use oat\oatbox\cache\SimpleCache; use oat\oatbox\service\ConfigurableService; @@ -90,7 +91,7 @@ public function getPersistence(): common_persistence_GraphPersistence public function getCache(): SimpleCache { - return $this->getServiceLocator()->get('generis/PropertyCache'); + return $this->getServiceLocator()->get(PropertyCache::SERVICE_ID); } /** diff --git a/test/OntologyMockTrait.php b/test/OntologyMockTrait.php index c48c64011..71532e8c1 100644 --- a/test/OntologyMockTrait.php +++ b/test/OntologyMockTrait.php @@ -40,6 +40,7 @@ use oat\oatbox\user\UserLanguageServiceInterface; use Prophecy\Argument; use Psr\Log\LoggerInterface; +use oat\oatbox\cache\PropertyCache; trait OntologyMockTrait { @@ -101,7 +102,7 @@ private function setupOntology(Ontology $onto) Bin2HexUriProvider::OPTION_NAMESPACE => 'http://ontology.mock/bin2hex#' ]), SimpleCache::SERVICE_ID => new NoCache(), - 'generis/PropertyCache' => new NoCache(), + PropertyCache::SERVICE_ID => new NoCache(), DriverConfigurationFeeder::SERVICE_ID => new DriverConfigurationFeeder(), EventAggregator::SERVICE_ID => $eventAggregator ]); From a3110d9c3457790ceb64ac77ed14c1b8f497a6d8 Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Fri, 1 Dec 2023 18:35:25 +0200 Subject: [PATCH 12/13] feat: decrease query count by cacheing some RDF property fields --- .../Version202312011658572348_generis.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 migrations/Version202312011658572348_generis.php diff --git a/migrations/Version202312011658572348_generis.php b/migrations/Version202312011658572348_generis.php new file mode 100644 index 000000000..a5c1f627d --- /dev/null +++ b/migrations/Version202312011658572348_generis.php @@ -0,0 +1,64 @@ +getExtension(); + + try { + $this->getServiceManager() + ->get(PersistenceManager::SERVICE_ID) + ->getPersistenceById('redis'); + + $config = new PropertyCache([ + PropertyCache::OPTION_PERSISTENCE => 'redis' + ]); + } catch (\Exception $e) { + $config = new PropertyCache([ + PropertyCache::OPTION_PERSISTENCE => 'cache' + ]); + } + + $confKey = 'PropertyCache'; + + if (!$extension->hasConfig($confKey)) { + $extension->setConfig($confKey, $config); + } + } + + public function down( + Schema $schema + ): void { + $extension = $this->getExtension(); + $confKey = 'PropertyCache'; + + if ($extension->hasConfig($confKey)) { + $extension->unsetConfig($confKey); + } + } + + private function getExtension(): Extension + { + return $this->getServiceLocator() + ->getContainer() + ->get(ExtensionsManager::SERVICE_ID) + ->getExtensionById('generis'); + } +} From 777aca2912254c19b77084064c32ddadd3e1cb8b Mon Sep 17 00:00:00 2001 From: Makar Sichevoi Date: Wed, 6 Dec 2023 15:06:18 +0200 Subject: [PATCH 13/13] feat: decrease query count by cacheing some RDF property fields --- core/kernel/classes/class.Property.php | 4 ++-- .../persistence/{Cache.php => Cacheable.php} | 2 +- .../smoothsql/class.SmoothModel.php | 4 ++-- .../persistence/starsql/class.StarModel.php | 4 ++-- .../Version202312011658572348_generis.php | 23 ++----------------- 5 files changed, 9 insertions(+), 28 deletions(-) rename core/kernel/persistence/{Cache.php => Cacheable.php} (97%) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index c07dc3491..3bc6a5780 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -31,7 +31,7 @@ use oat\generis\model\GenerisRdf; use oat\generis\model\OntologyRdfs; use oat\generis\model\resource\DependsOnPropertyCollection; -use oat\generis\model\kernel\persistence\Cache; +use oat\generis\model\kernel\persistence\Cacheable; /** * uriProperty must be a valid property otherwis return false, add this as a @@ -504,6 +504,6 @@ protected function generateIsMultipleKey(string $uri): string */ protected function supportCache(): bool { - return $this->getModel() instanceof Cache; + return $this->getModel() instanceof Cacheable; } } diff --git a/core/kernel/persistence/Cache.php b/core/kernel/persistence/Cacheable.php similarity index 97% rename from core/kernel/persistence/Cache.php rename to core/kernel/persistence/Cacheable.php index d712e5509..ef4f8d887 100755 --- a/core/kernel/persistence/Cache.php +++ b/core/kernel/persistence/Cacheable.php @@ -22,7 +22,7 @@ use oat\oatbox\cache\SimpleCache; -interface Cache +interface Cacheable { public function getCache(): SimpleCache; } diff --git a/core/kernel/persistence/smoothsql/class.SmoothModel.php b/core/kernel/persistence/smoothsql/class.SmoothModel.php index 44a75b15e..04e91bcdf 100755 --- a/core/kernel/persistence/smoothsql/class.SmoothModel.php +++ b/core/kernel/persistence/smoothsql/class.SmoothModel.php @@ -21,7 +21,7 @@ use oat\generis\model\data\ModelManager; use oat\generis\model\data\Ontology; -use oat\generis\model\kernel\persistence\Cache; +use oat\generis\model\kernel\persistence\Cacheable; use oat\generis\model\kernel\persistence\smoothsql\install\SmoothRdsModel; use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\generis\persistence\sql\SchemaCollection; @@ -39,7 +39,7 @@ class core_kernel_persistence_smoothsql_SmoothModel extends ConfigurableService implements Ontology, SchemaProviderInterface, - Cache + Cacheable { public const OPTION_PERSISTENCE = 'persistence'; public const OPTION_READABLE_MODELS = 'readable'; diff --git a/core/kernel/persistence/starsql/class.StarModel.php b/core/kernel/persistence/starsql/class.StarModel.php index d9d146d23..6c77c3d8d 100644 --- a/core/kernel/persistence/starsql/class.StarModel.php +++ b/core/kernel/persistence/starsql/class.StarModel.php @@ -20,13 +20,13 @@ use oat\generis\model\data\ModelManager; use oat\generis\model\data\Ontology; -use oat\generis\model\kernel\persistence\Cache; +use oat\generis\model\kernel\persistence\Cacheable; use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\oatbox\cache\PropertyCache; use oat\oatbox\cache\SimpleCache; use oat\oatbox\service\ConfigurableService; -class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology, Cache +class core_kernel_persistence_starsql_StarModel extends ConfigurableService implements Ontology, Cacheable { public const OPTION_PERSISTENCE = 'persistence'; public const OPTION_READABLE_MODELS = 'readable'; diff --git a/migrations/Version202312011658572348_generis.php b/migrations/Version202312011658572348_generis.php index a5c1f627d..896d86c38 100644 --- a/migrations/Version202312011658572348_generis.php +++ b/migrations/Version202312011658572348_generis.php @@ -20,8 +20,6 @@ public function getDescription(): string public function up(Schema $schema): void { - $extension = $this->getExtension(); - try { $this->getServiceManager() ->get(PersistenceManager::SERVICE_ID) @@ -36,29 +34,12 @@ public function up(Schema $schema): void ]); } - $confKey = 'PropertyCache'; - - if (!$extension->hasConfig($confKey)) { - $extension->setConfig($confKey, $config); - } + $this->registerService(PropertyCache::SERVICE_ID, $config); } public function down( Schema $schema ): void { - $extension = $this->getExtension(); - $confKey = 'PropertyCache'; - - if ($extension->hasConfig($confKey)) { - $extension->unsetConfig($confKey); - } - } - - private function getExtension(): Extension - { - return $this->getServiceLocator() - ->getContainer() - ->get(ExtensionsManager::SERVICE_ID) - ->getExtensionById('generis'); + $this->getServiceManager()->unregister(PropertyCache::SERVICE_ID); } }