Make fetching hits slightly faster

This commit is contained in:
Ruben 2017-06-16 12:42:57 +02:00
parent a57f9528d7
commit 88b154826c
3 changed files with 15 additions and 4 deletions

View file

@ -31,8 +31,10 @@ $classes = $metadatas;
// ); // );
// $tool->getCreateDatabaseSQL(); // $tool->getCreateDatabaseSQL();
$queries = $tool->getCreateSchemaSQL($classes); // $queries = $tool->getCreateSchemaSQL($classes);
// $queries = $tool->getUpdateSchemaSql($classes); $queries = $tool->getUpdateSchemaSql($classes);
var_dump($queries);
die()
foreach($queries as $sql){ echo "$sql;\n"; } foreach($queries as $sql){ echo "$sql;\n"; }
// updateSchema // updateSchema
$tool->updateSchema($classes); $tool->updateSchema($classes);

View file

@ -9,7 +9,15 @@ use Doctrine\Common\Collections\ArrayCollection;
/** /**
* Hit of a target and the facial parameters at the moment of the hit * 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
* @ORM\Entity(repositoryClass="EmotionHero\Models\HitRepository") * @ORM\Entity(repositoryClass="EmotionHero\Models\HitRepository")
*/ */

View file

@ -39,7 +39,8 @@ class HitRepository extends EntityRepository
} }
$query = $this->_em->createQuery( $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([ ->setParameters([
'score' => $score, 'score' => $score,