Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #213 from shouze/perf-retrieve-component-with-index
Browse files Browse the repository at this point in the history
perf: retrieve component by using indexed column
  • Loading branch information
stephpy authored Jun 20, 2019
2 parents 5937b64 + f840e31 commit a33e11e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.1
- 7.2
- 7.3

install: composer install -n

Expand Down
8 changes: 3 additions & 5 deletions Driver/ORM/ActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ public function findOrCreateComponent($model, $identifier = null, $flush = true)

$component = $this->getComponentRepository()
->createQueryBuilder('c')
->where('c.model = :model')
->andWhere('c.identifier = :identifier')
->setParameter('model', $resolvedComponentData->getModel())
->setParameter('identifier', serialize($resolvedComponentData->getIdentifier()))
->where('c.hash = :hash')
->setParameter('hash', $resolvedComponentData->getHash())
->getQuery()
->getOneOrNullResult()
;
Expand Down Expand Up @@ -123,7 +121,7 @@ public function findComponents(array $hashes)
$qb = $this->getComponentRepository()->createQueryBuilder('c');

return $qb->where(
$qb->expr()->in('c.hash', $hashes)
$qb->expr()->in('c.hash', $hashes)
)
->getQuery()
->getResult()
Expand Down
25 changes: 15 additions & 10 deletions Tests/Units/Driver/ORM/ActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public function testCreateComponent()
->and($componentClass = 'Spy\Timeline\Model\Component')
->and($actionComponentClass = 'Spy\Timeline\Model\ActionComponent')
->and($actionManager = new TestedModel($objectManager, $resultBuilder, $actionClass, $componentClass, $actionComponentClass))
->exception(function () use ($actionManager) {
$actionManager->getComponentDataResolver();
}
->exception(
function () use ($actionManager) {
$actionManager->getComponentDataResolver();
}
)->hasMessage('Component data resolver not set')
->and($actionManager->setComponentDataResolver($componentDataResolver))
->when($result = $actionManager->createComponent($model, $identifier))
Expand Down Expand Up @@ -67,16 +68,22 @@ public function testfindOrCreateComponentWithExistingComponent()
return $queryBuilder;
})
//here we return the component as result of the query
->and($this->calling($query)->getOneOrNullResult = function () use ($component) { return $component;})
->and($this->calling($query)->getOneOrNullResult = function () use ($component) {
return $component;
})
//grouping those did not work the method was __call
->and($this->calling($queryBuilder)->where = function () use ($queryBuilder) { return $queryBuilder;})
->and($this->calling($queryBuilder)->where = function () use ($queryBuilder) {
return $queryBuilder;
})
->and($this->calling($queryBuilder)->andWhere = function () use ($queryBuilder) {
return $queryBuilder;
})
->and($this->calling($queryBuilder)->setParameter = function () use ($queryBuilder) {
return $queryBuilder;
})
->and($this->calling($queryBuilder)->getQuery = function () use ($query) { return $query;})
->and($this->calling($queryBuilder)->getQuery = function () use ($query) {
return $query;
})
->and($actionClass = 'Spy\Timeline\Model\Action')
->and($componentClass = 'Spy\Timeline\Model\Component')
->and($actionComponentClass = 'Spy\Timeline\Model\ActionComponent')
Expand All @@ -87,10 +94,8 @@ public function testfindOrCreateComponentWithExistingComponent()
})
->when($result = $actionManager->findOrCreateComponent('user', 1))
->mock($componentDataResolver)->call('resolveComponentData')->withArguments($resolve)->exactly(1)
->mock($queryBuilder)->call('where')->withArguments('c.model = :model')->exactly(1)
->mock($queryBuilder)->call('andWhere')->withArguments('c.identifier = :identifier')->exactly(1)
->mock($queryBuilder)->call('setParameter')->withArguments('model', $resolvedComponentData->getModel())->exactly(1)
->mock($queryBuilder)->call('setParameter')->withArguments('identifier', serialize($resolvedComponentData->getIdentifier()))->exactly(1)
->mock($queryBuilder)->call('where')->withArguments('c.hash = :hash')->exactly(1)
->mock($queryBuilder)->call('setParameter')->withArguments('hash', $resolvedComponentData->getHAsh())->exactly(1)
->object($result)->isEqualTo($component)
;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}],
"require": {
"php": "^7.1",
"stephpy/timeline": "^1.0",
"stephpy/timeline": "^1.2",
"symfony/framework-bundle": "~2.0|~3.0|~4.0",
"symfony/options-resolver": "~2.0|~3.0|~4.0"
},
Expand Down

0 comments on commit a33e11e

Please sign in to comment.