-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2023(original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\tao\migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use oat\generis\model\data\event\CacheWarmupEvent; | ||
use oat\generis\model\data\event\ResourceDeleted; | ||
use oat\generis\model\data\event\ResourceUpdated; | ||
use oat\oatbox\event\EventManager; | ||
use oat\tao\model\listener\ClassPropertiesChangedListener; | ||
use oat\tao\model\listener\ClassPropertyCacheWarmupListener; | ||
use oat\tao\model\listener\ClassPropertyRemovedListener; | ||
use oat\tao\scripts\tools\migrations\AbstractMigration; | ||
|
||
final class Version202312011610042234_tao extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Register property cache warmup and modify listeners.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
/** @var EventManager $eventManager */ | ||
$eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID); | ||
$eventManager->attach( | ||
CacheWarmupEvent::class, | ||
[ClassPropertyCacheWarmupListener::class, 'handleEvent'] | ||
); | ||
$eventManager->attach( | ||
ResourceDeleted::class, | ||
[ClassPropertyRemovedListener::SERVICE_ID, 'handleDeletedEvent'] | ||
); | ||
$eventManager->attach( | ||
ResourceUpdated::class, | ||
[ClassPropertiesChangedListener::SERVICE_ID, 'handleUpdatedEvent'] | ||
); | ||
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
/** @var EventManager $eventManager */ | ||
$eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID); | ||
$eventManager->detach( | ||
CacheWarmupEvent::class, | ||
[ClassPropertyCacheWarmupListener::class, 'handleEvent'] | ||
); | ||
$eventManager->detach( | ||
ResourceDeleted::class, | ||
[ClassPropertyRemovedListener::SERVICE_ID, 'handleDeletedEvent'] | ||
); | ||
$eventManager->detach( | ||
ResourceUpdated::class, | ||
[ClassPropertiesChangedListener::SERVICE_ID, 'handleUpdatedEvent'] | ||
); | ||
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
models/classes/listener/ClassPropertyCacheWarmupListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2023 (original work) Open Assessment Technologies SA; | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\tao\model\listener; | ||
|
||
use oat\generis\Helper\PropertyCache; | ||
use oat\generis\model\data\event\CacheWarmupEvent; | ||
use oat\generis\model\data\Ontology; | ||
use oat\oatbox\reporting\Report; | ||
|
||
class ClassPropertyCacheWarmupListener | ||
{ | ||
public function __construct(Ontology $model) | ||
{ | ||
$this->model = $model; | ||
} | ||
|
||
public function handleEvent(CacheWarmupEvent $event): void | ||
{ | ||
$class = new \core_kernel_classes_Class('http://www.w3.org/1999/02/22-rdf-syntax-ns#Property'); | ||
$properties = $class->getInstances(true); | ||
$properties = array_unique(array_keys($properties)); | ||
|
||
PropertyCache::warmupCachedValuesByProperties($properties); | ||
|
||
$event->addReport(Report::createInfo('Generated property cache.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2023 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\tao\model\listener; | ||
|
||
use common_ext_ExtensionsManager; | ||
use oat\generis\model\data\Ontology; | ||
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; | ||
use oat\oatbox\cache\SimpleCache; | ||
use oat\tao\model\ClientLibConfigRegistry; | ||
use oat\tao\model\featureFlag\Listener\FeatureFlagCacheWarmupListener; | ||
use oat\tao\model\featureFlag\Repository\FeatureFlagRepository; | ||
use oat\tao\model\featureFlag\Repository\FeatureFlagRepositoryInterface; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class PropertyServiceProvider implements ContainerServiceProviderInterface | ||
{ | ||
public function __invoke(ContainerConfigurator $configurator): void | ||
{ | ||
$services = $configurator->services(); | ||
|
||
$services | ||
->set(ClassPropertyCacheWarmupListener::class, ClassPropertyCacheWarmupListener::class) | ||
->public() | ||
->args( | ||
[ | ||
service(Ontology::SERVICE_ID) | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters