如何加快完整的日历加载时间

时间:2014-03-12 19:47:20

标签: javascript php jquery fullcalendar

我在我的网站上使用完整的日历,并且我发现随着时间的推移添加更多事件,它的加载速度会逐渐加快。它已经达到了点击页面后显示事件需要6-7秒的程度。

我尝试了许多不同的调整来帮助加快速度,但都无济于事。这是我用来加载事件的代码:

$startdate = $_GET['start'];
$enddate = $_GET['end'];
$location = $_GET['location'];

$calendar = mysql_query('SELECT *, jobs.id as jobid, jobs.workOrder as jobWorkOrder, jobs.serviceType as serviceType, jobs.status as jobstatus, UNIX_TIMESTAMP(jobs.start_date) AS jobDate FROM jobs JOIN clients ON clients.id = client_id WHERE jobs.status <> 2 AND UNIX_TIMESTAMP(start_date) BETWEEN "' . $startdate . '" AND "'. $enddate . '" AND jobs.location = "'.$location.'"');

$calendar_array = array();
while ($row = mysql_fetch_array($calendar)) {
    $jobrecurringtype = mysql_fetch_array(mysql_query('SELECT frequency FROM jobs_recurring WHERE id = "' . $row['recurring_id'] . '"'));

    //check for first-time jobs
    $sql = 'SELECT COUNT(jobs.id) AS amount
            FROM jobs
            WHERE client_id = "' . $row['client_id'] . '"
            AND start_date < "' . date('Y-m-d h:i:s', $row['jobDate']) . '"';
    $jobs = mysql_fetch_array(mysql_query($sql));

    if($jobrecurringtype['frequency'] == '') { //non-recurring jobs 

        if(strpos($row['serviceType'],'fix it') === true){//add fix-it colors
        switch (jobNeedsProviders($row['jobid'])) {
            case false:
                $status = 'fix-it-confirmed';
                break;
            case true:
                $status = 'fix-it-unconfirmed';
                break;
        }
        } else {
        switch (jobNeedsProviders($row['jobid'])) {
            case false:
                $status = (($jobs['amount'] == 0) ? 'first-time-confirmed' : 'standard-confirmed');
                break;
            case true:
                $status = (($jobs['amount'] == 0) ? 'first-time-unconfirmed' : 'standard-unconfirmed');
                break;
        }
        }//end else


    } else { // Recurring jobs
        switch (jobNeedsProviders($row['jobid'])) {
            case false:
                if($row['dateAdded'] > '2010-11-01' && $jobs['amount'] == 0) {$status = 'first-time-confirmed';} else {$status = strtolower($jobrecurringtype['frequency']) . '-confirmed';}
                break;
            case true:
                if($row['dateAdded'] > '2010-11-01' && $jobs['amount'] == 0) {$status = 'first-time-unconfirmed';} else {$status = strtolower($jobrecurringtype['frequency']) . '-unconfirmed';}
                break;
        }
    }

    $recurring = ($row['recurring_id'] != 0 && $row['recurring_overridden'] != 1 ? 'recurring' : '');

    if($row['businessName'] != ''){$title = stripslashes($row['businessName']);}else{$title = stripslashes($row['firstName']) . ' ' . stripslashes($row['lastName']);}

    $calendar_array[] = array(
        'id' => stripslashes('job' . $row['jobid']),
        'title' => $title,
        'start' => $row['start_date'],
        'end' => date("Y-M-d H:i:s", strtotime("+1 hour", strtotime($row['start_date']))),
        'className' => array($status, $recurring, $row['jobWorkOrder']),
        'url' => "/manage/jobs_manage.php?jobmanage=1&jobedit=1&id=" . $row['jobid'],
        'allDay' => false);
}
    print json_encode($calendar_array);
}

function jobNeedsProviders($id){
    $row = mysql_fetch_array(mysql_query('SELECT SUM(IF(provider_id=0,1,0)) AS fillers, COUNT(provider_id) AS totalProviders FROM `job_providers` WHERE job_id = ' . $id));
    if($row['fillers'] > 0 || $row['totalProviders'] == 0) {
        return true;
    } else {
        return false;
    }

正如您所看到的,我在while循环中运行了许多数据库查询,我怀疑这可能是我的问题的根源。但是,我不确定我可以采取哪种替代方法来解决这个问题。任何帮助将不胜感激。

0 个答案:

没有答案