Cupara
Well-known member
I'm having huge load times when grabbing data from 4 different tables. It ranges around 60-66 secs and that is way too high for anyone to run on my site. I'm not sure if it is because my host is limiting us or if my code has flaws.
I managed to get the Queries down to 16 by the way.
So here goes, the page causing this issue is:
Here is my tips entity:
Any input greatly appreciated.
I managed to get the Queries down to 16 by the way.
So here goes, the page causing this issue is:
PHP:
public function actionArchived()
{
$options = \XF::options();
$db = \XF::db();
$visitor = \XF::visitor();
$app = \XF::app();
$tipsFinder = \XF::finder('BetClever\Tipsters:Tips');
$archivePage = max(1, $this->filterPage());
$archivePerPage = 15;
$tipsArchived = $tipsFinder->limitByPage($archivePage, $archivePerPage)->where('status', 'NOT LIKE', '2')->with('Events', 'User', 'Sports', 'Leagues')->fetch();
$archiveTotal = $tipsFinder->total();
$maxPage = ceil($archiveTotal / $archivePerPage);
$this->assertCanonicalUrl($this->buildLink('home/archived', '', ['page' => $archivePage]));
$this->assertValidPage($archivePage, $archivePerPage, $archiveTotal, 'home/archived');
$viewParams = [
'tipsArchived' => $tipsArchived,
'archiveTotal' => $archiveTotal,
'archivePage' => $archivePage,
'archivePerPage' => $archivePerPage,
'maxPage' => $maxPage
];
return $this->view('BetClever\Tipsters:View', 'bc_home_archived_view', $viewParams);
}
Here is my tips entity:
PHP:
<?php
namespace BetClever\Tipsters\Entity;
use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;
class Tips extends Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = 'tips';
$structure->shortName = 'BetClever\Tipsters:Tips';
$structure->contentType = 'bc_tips';
$structure->primaryKey = 'id';
$structure->columns = [
'id' => ['type' => self::UINT, 'maxLength' => 50, 'autoIncrement' => true],
'sport_id' => ['type' => self::UINT, 'maxLength' => 50],
'league_id' => ['type' => self::UINT, 'maxLength' => 50],
'match_id' => ['type' => self::UINT, 'maxLength' => 50],
'match_date' => ['type' => self::UINT],
'match_time' => ['type' => self::UINT, 'nullable' => true],
'bet_name' => ['type' => self::STR, 'maxLength' => 255],
'bet_id' => ['type' => self::UINT, 'maxLength' => 50],
'choice_id' => ['type' => self::UINT, 'maxLength' => 50],
'choice_name' => ['type' => self::STR, 'maxLength' => 255],
'odd' => ['type' => self::FLOAT],
'stake' => ['type' => self::UINT, 'maxLength' => 11],
'description' => ['type' => self::STR],
'other_text' => ['type' => self::STR, 'nullable' => true],
'user_id' => ['type' => self::UINT, 'maxLength' => 11],
'created_on' => ['type' => self::UINT],
'status' => ['type' => self::UINT, 'maxLength' => 11],
'winnings' => ['type' => self::FLOAT],
'views' => ['type' => self::UINT, 'maxLength' => 30],
'result' => ['type' => self::STR, 'maxLength' => 50, 'nullable' => true]
];
$structure->behaviors = [
];
$structure->getters = [
];
$structure->relations = [
'Sports' => [
'entity' => 'BetClever\Tipsters:Sports',
'type' => self::TO_ONE,
'conditions' => 'sport_id',
'primary' => true
],
'Leagues' => [
'entity' => 'BetClever\Tipsters:Leagues',
'type' => self::TO_ONE,
'conditions' => 'league_id',
'primary' => true
],
'Bets' => [
'entity' => 'BetClever\Tipsters:Bets',
'type' => self::TO_ONE,
'conditions' => 'bet_id',
'primary' => true
],
'User' => [
'entity' => 'XF:User',
'type' => self::TO_ONE,
'conditions' => 'user_id',
'primary' => true
],
'Events' => [
'entity' => 'BetClever\Tipsters:Events',
'type' => self::TO_ONE,
'conditions' => 'match_id',
'primary' => true,
'with' => 'Teams'
],
'TipReports' => [
'entity' => 'BetClever\Tipsters:TipReports',
'type' => self::TO_MANY,
'conditions' => 'tip_id',
'primary' => true
]
];
$structure->options = [
];
return $structure;
}
protected function _postDelete()
{
$tipsRepo = \XF::repository('BetClever\Tipsters:Tips');
$finder = \XF::em()->find('BetClever\Tipsters:Tips', $this->id);
if ($finder)
{
$finder->delete($this->id);
}
}
}
Any input greatly appreciated.
Last edited: