Ignore:
Timestamp:
01/03/13 08:46:17 (7 years ago)
Author:
acoutinho
Message:

Ticket #3259 - Otimizar carregamento de eventos no modulo ExpressoCalendar?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/calendar/interceptors/DBMapping.php

    r7696 r7702  
    194194 
    195195    public function findSchedulable(&$uri, &$params, &$criteria, $original) { 
    196         if (isset($criteria['filter'][2][1]) && $criteria['filter'][2][1] == 'calendar') { 
    197  
    198             $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", ' 
    199                 .'calendar_object.dtstart as "startTime", calendar_object.summary as "summary", ' 
    200                 .'calendar_object.description as "description", calendar_object.dtend as "endTime" , ' 
    201         .'calendar_object.priority as "priority", calendar_object.due as "due", ' 
    202         .'calendar_object.percentage as "percentage", calendar_object.status as "status", ' 
    203                 .'calendar_object.location as "location", calendar_object.allday as "allDay", ' 
    204                 .'calendar_object.transp as "transparent", calendar_object.class_id as "class", ' 
    205                 .'calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart", ' 
    206                 .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", ' 
    207                 .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", ' 
    208                 .'calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as ' 
    209                 .'calendar FROM calendar_to_calendar_object , calendar_object ' 
    210                 .'WHERE ( calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['filter'][2][2]) . '\')) ' 
    211                 .'AND calendar_to_calendar_object.calendar_object_id = calendar_object.id ' 
    212         .'AND calendar_object.id NOT IN(select calendar_object_task_id from calendar_task_to_activity_object where owner = \'' . Config::me('uidNumber') . '\') ';       
    213              
    214             if(isset($criteria['searchEvent']) && $criteria['searchEvent']){ 
    215                 $where = 'AND (((upper("summary") like upper(\'%'.$criteria['filter'][1][1][2].'%\') OR upper("description") like upper(\'%'.$criteria['filter'][1][2][2].'%\')))) ORDER BY dtstart LIMIT '.$criteria['limit'].'  OFFSET '.$criteria['offset'].' '; 
    216                 $params = Controller::service('PostgreSQL')->execResultSql($sql.$where); 
    217  
    218             }else{ 
    219                 $start = array( $criteria['filter'][1][1][1][2] , $criteria['filter'][1][2][1][2], $criteria['filter'][1][3][1][2] ); 
    220                 $end = array( $criteria['filter'][1][1][2][2] , $criteria['filter'][1][2][2][2], $criteria['filter'][1][3][2][2] ); 
    221  
    222                 $ids = array(); 
    223                 $occ = array(); 
    224  
    225                 if ($occurrences = self::checkOccurrences($start[0], $end[0], $criteria['filter'][2][2])) 
    226                     foreach ($occurrences as $id => $occurrence) { 
    227                         $ids[] = $id; 
    228                         $occ[] = $occurrence; 
    229                     }    
    230  
    231                 $where = 'AND ((range_end >= \'' . $start[0] . '\' AND range_end <= \'' . $end[0] . '\') OR ' 
    232                         .'(range_start >= \'' . $start[1] . '\' AND range_start <= \'' . $end[1] . '\') OR ' 
    233                         .'(range_start <= \'' . $start[2] . '\' AND range_end >= \'' . $end[2] . '\')) ' 
    234                 .(!empty($ids) ? ' ' .'AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\') ' : ' ') 
    235                 .'AND calendar_object.dtstart NOT IN (SELECT calendar_repeat_occurrence.occurrence from calendar_repeat_occurrence, ' 
    236                 .'calendar_repeat where (calendar_repeat_occurrence.repeat_id = calendar_repeat.id) ' 
    237                 .'AND (calendar_repeat.object_id = calendar_object.id))'; 
    238  
    239                 $params = Controller::service('PostgreSQL')->execResultSql($sql.$where); 
    240                 $params = array_merge($params, $occ);            
    241             } 
    242             $params = self::deepnessFindEvent($uri, $params, $criteria, $original); 
    243             return false; 
    244         } 
     196        if (isset($criteria['customQuery']) && $criteria['customQuery'] == '1') { 
     197 
     198            $sql = ' SELECT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", ' 
     199            .'calendar_object.dtstart as "startTime", calendar_object.summary as "summary", ' 
     200            .'calendar_object.description as "description", calendar_object.dtend as "endTime" , ' 
     201            .'calendar_object.priority as "priority", calendar_object.due as "due", ' 
     202            .'calendar_object.percentage as "percentage", calendar_object.status as "status", ' 
     203            .'calendar_object.location as "location", calendar_object.allday as "allDay", ' 
     204            .'calendar_object.transp as "transparent", calendar_object.class_id as "class", ' 
     205            .'calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart", ' 
     206            .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", ' 
     207            .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", ' 
     208            .'calendar_object.tzid as "timezone" ,calendar_to_calendar_object.calendar_id as ' 
     209            .'calendar FROM calendar_to_calendar_object , calendar_object ' 
     210            .'WHERE ( calendar_to_calendar_object.calendar_id IN (\'' . implode('\',\'', $criteria['calendar']) . '\')) ' 
     211            .'AND calendar_to_calendar_object.calendar_object_id = calendar_object.id ' 
     212            .'AND calendar_object.id NOT IN(select calendar_object_task_id from calendar_task_to_activity_object where owner = \'' . Config::me('uidNumber') . '\') '; 
     213 
     214            if(isset($criteria['searchEvent']) && $criteria['searchEvent']){ 
     215                $where = 'AND (((upper("summary") like upper(\'%'.$criteria['filter'][1][1][2].'%\') OR upper("description") like upper(\'%'.$criteria['filter'][1][2][2].'%\')))) ORDER BY dtstart LIMIT '.$criteria['limit'].'  OFFSET '.$criteria['offset'].' '; 
     216                $params = Controller::service('PostgreSQL')->execResultSql($sql.$where); 
     217 
     218            }else{ 
     219                $start = $criteria['rangeStart']; 
     220                $end = $criteria['rangeEnd']; 
     221 
     222                $ids = array(); 
     223                $occ = array(); 
     224 
     225                if ($occurrences = self::checkOccurrences($start, $end, $criteria['calendar'])) 
     226                    foreach ($occurrences as $id => $occurrence) { 
     227                        $ids[] = $id; 
     228                        $occ[] = $occurrence; 
     229                    } 
     230 
     231                $where = 'AND ((range_end >= \'' . $start . '\' AND range_end <= \'' . $end . '\') OR ' 
     232                    .'(range_start >= \'' . $start . '\' AND range_start <= \'' . $end . '\') OR ' 
     233                    .'(range_start <= \'' . $start . '\' AND range_end >= \'' . $end . '\')) ' 
     234                .(!empty($ids) ? ' ' .'AND calendar_object.id NOT IN (\'' . implode('\',\'', $ids) . '\') ' : ' ') 
     235                .'AND calendar_object.dtstart NOT IN (SELECT calendar_repeat_occurrence.occurrence from calendar_repeat_occurrence, ' 
     236                .'calendar_repeat where (calendar_repeat_occurrence.repeat_id = calendar_repeat.id) ' 
     237                .'AND (calendar_repeat.object_id = calendar_object.id))'; 
     238 
     239                $params = Controller::service('PostgreSQL')->execResultSql($sql.$where); 
     240                $params = array_merge($params, $occ); 
     241            } 
     242 
     243 
     244            $params = self::deepnessFindEvent($uri, $params, $criteria, $original); 
     245            return false; 
     246        } 
    245247    } 
    246248 
     
    841843    } 
    842844 
     845    //TODO: Remover apos suporte a deepness na api 
     846    public function findDeepnessOne(&$uri, &$params, &$criteria, $original){ 
     847 
     848        if (isset($criteria['findOne']) && $criteria['findOne'] == '1') { 
     849 
     850            $sql = ' SELECT DISTINCT calendar_object.id as id ,calendar_object.cal_uid as "uid", calendar_object.type_id as "type", ' 
     851                .'calendar_object.dtstart as "startTime", calendar_object.summary as "summary", ' 
     852                .'calendar_object.description as "description", calendar_object.dtend as "endTime" , ' 
     853                .'calendar_object.priority as "priority", calendar_object.due as "due", ' 
     854                .'calendar_object.percentage as "percentage", calendar_object.status as "status", ' 
     855                .'calendar_object.location as "location", calendar_object.allday as "allDay", ' 
     856                .'calendar_object.transp as "transparent", calendar_object.class_id as "class", ' 
     857                .'calendar_object.repeat as "repeat", calendar_object.range_start as "rangeStart", ' 
     858                .'calendar_object.range_end as "rangeEnd", calendar_object.last_update as "lastUpdate", ' 
     859                .'calendar_object.dtstamp as "dtstamp", calendar_object.sequence as "sequence", ' 
     860                .'calendar_object.tzid as "timezone" ' 
     861                .'FROM calendar_object ' 
     862                .'WHERE ( calendar_object.id = '. $criteria['schedulable'] .')'; 
     863 
     864            $params = Controller::service('PostgreSQL')->execResultSql($sql); 
     865 
     866            $params = self::deepnessFindEvent($uri, $params, $criteria, $original); 
     867            return false; 
     868        } 
     869 
     870 
     871 
     872    } 
     873 
    843874    //TODO: Remover apos suporte a deepness na api  
    844875    public function deepnessFindEvent(&$uri, &$result, &$criteria, $original) { 
    845         if (isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) { 
     876        if ((isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0) ) { 
    846877 
    847878            $date = new DateTime('now', new DateTimeZone('UTC')); 
Note: See TracChangeset for help on using the changeset viewer.