Make fetching hits slightly faster
This commit is contained in:
parent
a57f9528d7
commit
88b154826c
3 changed files with 15 additions and 4 deletions
|
@ -31,8 +31,10 @@ $classes = $metadatas;
|
|||
// );
|
||||
|
||||
// $tool->getCreateDatabaseSQL();
|
||||
$queries = $tool->getCreateSchemaSQL($classes);
|
||||
// $queries = $tool->getUpdateSchemaSql($classes);
|
||||
// $queries = $tool->getCreateSchemaSQL($classes);
|
||||
$queries = $tool->getUpdateSchemaSql($classes);
|
||||
var_dump($queries);
|
||||
die()
|
||||
foreach($queries as $sql){ echo "$sql;\n"; }
|
||||
// updateSchema
|
||||
$tool->updateSchema($classes);
|
||||
|
|
|
@ -9,7 +9,15 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
/**
|
||||
* Hit of a target and the facial parameters at the moment of the hit
|
||||
*
|
||||
* @ORM\Table(name="hits")
|
||||
* @ORM\Table(name="hits", indexes={
|
||||
* @Index(name="imgAnger", columns={"hasImage", "anger"}),
|
||||
* @Index(name="imgContempt", columns={"hasImage", "contempt"}),
|
||||
* @Index(name="imgDisgust", columns={"hasImage", "disgust"}),
|
||||
* @Index(name="imgFear", columns={"hasImage", "fear"}),
|
||||
* @Index(name="imgJoy", columns={"hasImage", "joy"}),
|
||||
* @Index(name="imgSadness", columns={"hasImage", "sadness"}),
|
||||
* @Index(name="imgSurprise", columns={"hasImage", "surprise"}),
|
||||
* })
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="EmotionHero\Models\HitRepository")
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,8 @@ class HitRepository extends EntityRepository
|
|||
}
|
||||
|
||||
$query = $this->_em->createQuery(
|
||||
"SELECT h, ABS(:score - h.emotions.$emotionField) as HIDDEN distance, RAND() AS HIDDEN lala FROM ".Hit::class." h WHERE h.hasImage = :has ORDER BY distance ASC, lala"
|
||||
// add BETWEEN so we can use _some_ keying to improve performance.
|
||||
"SELECT h, ABS(:score - h.emotions.$emotionField) as HIDDEN distance, RAND() AS HIDDEN lala FROM ".Hit::class." h WHERE h.hasImage = :has AND h.emotions.$emotionField BETWEEN :score - 5 AND :score + 5 ORDER BY distance ASC, lala"
|
||||
)
|
||||
->setParameters([
|
||||
'score' => $score,
|
||||
|
|
Loading…
Reference in a new issue