Skip to content

Commit a33e11e

Browse files
authored
Merge pull request #213 from shouze/perf-retrieve-component-with-index
perf: retrieve component by using indexed column
2 parents 5937b64 + f840e31 commit a33e11e

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.1
55
- 7.2
6+
- 7.3
67

78
install: composer install -n
89

Driver/ORM/ActionManager.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ public function findOrCreateComponent($model, $identifier = null, $flush = true)
8080

8181
$component = $this->getComponentRepository()
8282
->createQueryBuilder('c')
83-
->where('c.model = :model')
84-
->andWhere('c.identifier = :identifier')
85-
->setParameter('model', $resolvedComponentData->getModel())
86-
->setParameter('identifier', serialize($resolvedComponentData->getIdentifier()))
83+
->where('c.hash = :hash')
84+
->setParameter('hash', $resolvedComponentData->getHash())
8785
->getQuery()
8886
->getOneOrNullResult()
8987
;
@@ -123,7 +121,7 @@ public function findComponents(array $hashes)
123121
$qb = $this->getComponentRepository()->createQueryBuilder('c');
124122

125123
return $qb->where(
126-
$qb->expr()->in('c.hash', $hashes)
124+
$qb->expr()->in('c.hash', $hashes)
127125
)
128126
->getQuery()
129127
->getResult()

Tests/Units/Driver/ORM/ActionManager.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public function testCreateComponent()
2626
->and($componentClass = 'Spy\Timeline\Model\Component')
2727
->and($actionComponentClass = 'Spy\Timeline\Model\ActionComponent')
2828
->and($actionManager = new TestedModel($objectManager, $resultBuilder, $actionClass, $componentClass, $actionComponentClass))
29-
->exception(function () use ($actionManager) {
30-
$actionManager->getComponentDataResolver();
31-
}
29+
->exception(
30+
function () use ($actionManager) {
31+
$actionManager->getComponentDataResolver();
32+
}
3233
)->hasMessage('Component data resolver not set')
3334
->and($actionManager->setComponentDataResolver($componentDataResolver))
3435
->when($result = $actionManager->createComponent($model, $identifier))
@@ -67,16 +68,22 @@ public function testfindOrCreateComponentWithExistingComponent()
6768
return $queryBuilder;
6869
})
6970
//here we return the component as result of the query
70-
->and($this->calling($query)->getOneOrNullResult = function () use ($component) { return $component;})
71+
->and($this->calling($query)->getOneOrNullResult = function () use ($component) {
72+
return $component;
73+
})
7174
//grouping those did not work the method was __call
72-
->and($this->calling($queryBuilder)->where = function () use ($queryBuilder) { return $queryBuilder;})
75+
->and($this->calling($queryBuilder)->where = function () use ($queryBuilder) {
76+
return $queryBuilder;
77+
})
7378
->and($this->calling($queryBuilder)->andWhere = function () use ($queryBuilder) {
7479
return $queryBuilder;
7580
})
7681
->and($this->calling($queryBuilder)->setParameter = function () use ($queryBuilder) {
7782
return $queryBuilder;
7883
})
79-
->and($this->calling($queryBuilder)->getQuery = function () use ($query) { return $query;})
84+
->and($this->calling($queryBuilder)->getQuery = function () use ($query) {
85+
return $query;
86+
})
8087
->and($actionClass = 'Spy\Timeline\Model\Action')
8188
->and($componentClass = 'Spy\Timeline\Model\Component')
8289
->and($actionComponentClass = 'Spy\Timeline\Model\ActionComponent')
@@ -87,10 +94,8 @@ public function testfindOrCreateComponentWithExistingComponent()
8794
})
8895
->when($result = $actionManager->findOrCreateComponent('user', 1))
8996
->mock($componentDataResolver)->call('resolveComponentData')->withArguments($resolve)->exactly(1)
90-
->mock($queryBuilder)->call('where')->withArguments('c.model = :model')->exactly(1)
91-
->mock($queryBuilder)->call('andWhere')->withArguments('c.identifier = :identifier')->exactly(1)
92-
->mock($queryBuilder)->call('setParameter')->withArguments('model', $resolvedComponentData->getModel())->exactly(1)
93-
->mock($queryBuilder)->call('setParameter')->withArguments('identifier', serialize($resolvedComponentData->getIdentifier()))->exactly(1)
97+
->mock($queryBuilder)->call('where')->withArguments('c.hash = :hash')->exactly(1)
98+
->mock($queryBuilder)->call('setParameter')->withArguments('hash', $resolvedComponentData->getHAsh())->exactly(1)
9499
->object($result)->isEqualTo($component)
95100
;
96101
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}],
1212
"require": {
1313
"php": "^7.1",
14-
"stephpy/timeline": "^1.0",
14+
"stephpy/timeline": "^1.2",
1515
"symfony/framework-bundle": "~2.0|~3.0|~4.0",
1616
"symfony/options-resolver": "~2.0|~3.0|~4.0"
1717
},

0 commit comments

Comments
 (0)