diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-02-06 20:08:37 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-02-10 14:33:07 +0100 |
commit | aebf6542140f593beb03a5c897f74d3ab057b362 (patch) | |
tree | e8235b77ec853bfe574b71205cdba975608ff8a2 /apps/workflowengine/tests | |
parent | e0946a1608283bd376f439906c50f3a4eb810839 (diff) | |
download | nextcloud-server-aebf6542140f593beb03a5c897f74d3ab057b362.tar.gz nextcloud-server-aebf6542140f593beb03a5c897f74d3ab057b362.zip |
perf(workflowengine): Cache query that is performed on every request
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/workflowengine/tests')
-rw-r--r-- | apps/workflowengine/tests/ManagerTest.php | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index 612495a5b6d..d3678b66bee 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -31,7 +31,10 @@ use OCA\WorkflowEngine\Entity\File; use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Manager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\Node\NodeCreatedEvent; use OCP\Files\IRootFolder; +use OCP\ICache; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; @@ -57,7 +60,6 @@ use Test\TestCase; * @group DB */ class ManagerTest extends TestCase { - /** @var Manager */ protected $manager; /** @var MockObject|IDBConnection */ @@ -76,6 +78,8 @@ class ManagerTest extends TestCase { protected $dispatcher; /** @var MockObject|IConfig */ protected $config; + /** @var MockObject|ICacheFactory */ + protected $cacheFactory; protected function setUp(): void { parent::setUp(); @@ -94,6 +98,7 @@ class ManagerTest extends TestCase { $this->session = $this->createMock(IUserSession::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->config = $this->createMock(IConfig::class); + $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->manager = new Manager( \OC::$server->getDatabaseConnection(), @@ -103,7 +108,8 @@ class ManagerTest extends TestCase { $this->logger, $this->session, $this->dispatcher, - $this->config + $this->config, + $this->cacheFactory ); $this->clearTables(); } @@ -283,11 +289,51 @@ class ManagerTest extends TestCase { }); } + public function testGetAllConfiguredEvents() { + $adminScope = $this->buildScope(); + $userScope = $this->buildScope('jackie'); + $entity = File::class; + + $opId5 = $this->invokePrivate( + $this->manager, + 'insertOperation', + ['OCA\WFE\OtherTestOp', 'Test04', [], 'foo', $entity, [NodeCreatedEvent::class]] + ); + $this->invokePrivate($this->manager, 'addScope', [$opId5, $userScope]); + + $allOperations = null; + + $cache = $this->createMock(ICache::class); + $cache + ->method('get') + ->willReturnCallback(function () use (&$allOperations) { + if ($allOperations) { + return $allOperations; + } + + return null; + }); + + $this->cacheFactory->method('createDistributed')->willReturn($cache); + $allOperations = $this->manager->getAllConfiguredEvents(); + $this->assertCount(1, $allOperations); + + $allOperationsCached = $this->manager->getAllConfiguredEvents(); + $this->assertCount(1, $allOperationsCached); + $this->assertEquals($allOperationsCached, $allOperations); + } + public function testUpdateOperation() { $adminScope = $this->buildScope(); $userScope = $this->buildScope('jackie'); $entity = File::class; + $cache = $this->createMock(ICache::class); + $cache->expects($this->exactly(4)) + ->method('remove') + ->with('events'); + $this->cacheFactory->method('createDistributed')->willReturn($cache); + $this->container->expects($this->any()) ->method('query') ->willReturnCallback(function ($class) { @@ -354,6 +400,12 @@ class ManagerTest extends TestCase { $userScope = $this->buildScope('jackie'); $entity = File::class; + $cache = $this->createMock(ICache::class); + $cache->expects($this->exactly(4)) + ->method('remove') + ->with('events'); + $this->cacheFactory->method('createDistributed')->willReturn($cache); + $opId1 = $this->invokePrivate( $this->manager, 'insertOperation', |