Jaxel
Well-known member
I have an entity, this is it's structure:
I need to get 50 entries from this entity. If I do the following finder query, it takes a good 50 seconds to process:
Now 50 seconds is a LOOOONG time.
If I instead do the following finder method, it processes in 0.0013 seconds... but results in 200 extra queries on my page.
Is there anything I can do to reduce the amount of queries, while maintaining speed?
Code:
public static function getStructure(Structure $structure)
{
$structure->table = 'ewr_torneo_matches';
$structure->shortName = 'EWR\Torneo:Match';
$structure->primaryKey = 'match_id';
$structure->columns = [
'event_id' => ['type' => self::UINT, 'required' => true],
'match_id' => ['type' => self::UINT, 'autoIncrement' => true],
'match_date' => ['type' => self::UINT, 'required' => true],
'match_round' => ['type' => self::INT, 'required' => true],
'match_scores' => ['type' => self::STR, 'required' => true],
'match_p1' => ['type' => self::STR, 'required' => true],
'match_p2' => ['type' => self::STR, 'required' => true],
'match_winner' => ['type' => self::STR, 'required' => true],
'match_media' => ['type' => self::STR, 'required' => false, 'default' => ''],
];
$structure->getters = [
'round' => true,
];
$structure->relations = [
'Event' => [
'entity' => 'EWR\Torneo:Event',
'type' => self::TO_ONE,
'conditions' => 'event_id',
'primary' => true,
],
'PlayerOne' => [
'entity' => 'EWR\Torneo:Result',
'type' => self::TO_ONE,
'conditions' => [
['event_id', '=', '$event_id'],
['result_extra', '=', '$match_p1']
],
],
'PlayerTwo' => [
'entity' => 'EWR\Torneo:Result',
'type' => self::TO_ONE,
'conditions' => [
['event_id', '=', '$event_id'],
['result_extra', '=', '$match_p2']
],
],
];
return $structure;
}
I need to get 50 entries from this entity. If I do the following finder query, it takes a good 50 seconds to process:
Code:
$entries = $matchRepo->findMatch()
->with([
'PlayerOne',
'PlayerOne.User',
'PlayerTwo',
'PlayerTwo.User'
])
->where('Event.league_id', $league->league_id)
->limitByPage($page, $perPage)
->fetch();
Now 50 seconds is a LOOOONG time.
If I instead do the following finder method, it processes in 0.0013 seconds... but results in 200 extra queries on my page.
Code:
$entries = $matchRepo->findMatch()
->where('Event.league_id', $league->league_id)
->limitByPage($page, $perPage)
->fetch();
Is there anything I can do to reduce the amount of queries, while maintaining speed?