Changeset 12118


Ignore:
Timestamp:
09/08/11 20:22:27 (8 years ago)
Author:
rvelices
Message:
  • reoptimize queries for MySql
  • week starts on monday/sunday applies also to weekly calendar
Location:
trunk/include
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_base.class.php

    r8728 r12118  
    221221 
    222222    $level_items = simple_hash_from_query($query, 'period', 'nb_images'); 
    223     $level_items = array_to_int($level_items); 
    224223 
    225224    if ( count($level_items)==1 and 
     
    293292    $current = implode('-', $page['chronology_date'] ); 
    294293    $upper_items = array_from_query( $query, 'period'); 
    295     $upper_items = array_to_int($upper_items); 
    296294 
    297295    usort($upper_items, 'version_compare'); 
  • trunk/include/calendar_monthly.class.php

    r8728 r12118  
    225225  assert( count($page['chronology_date']) == 0 ); 
    226226  $query=' 
    227 SELECT '.pwg_db_get_date_YYYYMM($this->date_field).' as period,' 
    228     .pwg_db_get_year($this->date_field).' as year, ' 
    229     .pwg_db_get_month($this->date_field).' as month,  
    230             count(distinct id) as count'; 
     227SELECT '.pwg_db_get_date_YYYYMM($this->date_field).' as period, 
     228  COUNT(distinct id) as count'; 
    231229  $query.= $this->inner_sql; 
    232230  $query.= $this->get_date_where(); 
    233231  $query.= ' 
    234   GROUP BY period, year, month 
    235   ORDER BY year DESC, month ASC'; 
     232  GROUP BY period 
     233  ORDER BY '.pwg_db_get_year($this->date_field).' DESC, '.pwg_db_get_month($this->date_field).' ASC'; 
    236234 
    237235  $result = pwg_query($query); 
     
    369367    $items[$day]['height'] = $row['height']; 
    370368    $items[$day]['dow'] = $row['dow']; 
    371  
    372     if ('sunday' == $conf['week_starts_on']) 
    373     { 
    374       $items[$day]['dow']++; 
    375     } 
    376369  } 
    377370 
     
    390383    $wday_labels = $lang['day']; 
    391384 
    392     // BEGIN - pass now in week starting Monday 
    393     if ($first_day_dow==0) 
    394     { 
    395       $first_day_dow = 6; 
    396     } 
    397     else 
    398     { 
    399       $first_day_dow -= 1; 
    400     } 
    401  
    402385    if ('monday' == $conf['week_starts_on']) 
    403386    { 
     387      if ($first_day_dow==0) 
     388      { 
     389        $first_day_dow = 6; 
     390      } 
     391      else 
     392      { 
     393        $first_day_dow -= 1; 
     394      } 
     395 
    404396      array_push( $wday_labels, array_shift($wday_labels) ); 
    405397    } 
    406     // END - pass now in week starting Monday 
    407398 
    408399    $cell_width = $conf['calendar_month_cell_width']; 
  • trunk/include/calendar_weekly.class.php

    r8728 r12118  
    4141  { 
    4242    parent::initialize($inner_sql); 
    43     global $lang; 
     43    global $lang, $conf; 
    4444    $week_no_labels=array(); 
    4545    for ($i=1; $i<=53; $i++) 
     
    6565    //Comment next lines for week starting on Sunday or if MySQL version<4.0.17 
    6666    //WEEK(date,5) = "0-53 - Week 1=the first week with a Monday in this year" 
    67     $this->calendar_levels[CWEEK]['sql'] = pwg_db_get_week($this->date_field, 5).'+1'; 
    68     $this->calendar_levels[CDAY]['sql'] = pwg_db_get_weekday($this->date_field); 
    69     array_push( $this->calendar_levels[CDAY]['labels'], 
    70                 array_shift( $this->calendar_levels[CDAY]['labels'] ) ); 
     67    if ('monday' == $conf['week_starts_on']) 
     68    { 
     69      $this->calendar_levels[CWEEK]['sql'] = pwg_db_get_week($this->date_field, 5).'+1'; 
     70      $this->calendar_levels[CDAY]['sql'] = pwg_db_get_weekday($this->date_field); 
     71      array_push( $this->calendar_levels[CDAY]['labels'], 
     72                  array_shift( $this->calendar_levels[CDAY]['labels'] ) ); 
     73    } 
    7174  } 
    7275 
  • trunk/include/functions_calendar.inc.php

    r8728 r12118  
    290290  pwg_debug('end initialize_calendar'); 
    291291} 
    292  
    293 function array_to_int($array) 
    294 { 
    295   $result = array(); 
    296   foreach ($array as $k => $v) 
    297   { 
    298     if ((int)$k==$k) 
    299     { 
    300       $key = (int) $k; 
    301     } 
    302     else 
    303     { 
    304       $key = $k; 
    305     } 
    306     if (is_array($v)) 
    307     { 
    308       $result[$key] = array_to_int($v); 
    309     } 
    310     else 
    311     { 
    312       if (is_int($v)) 
    313       { 
    314         $value = (int) $v; 
    315       } 
    316       else 
    317       { 
    318         $value = $v; 
    319       } 
    320       $result[$key] = $value; 
    321     } 
    322   } 
    323   return $result; 
    324 } 
    325292?> 
  • trunk/include/functions_tag.inc.php

    r11317 r12118  
    229229  } 
    230230  $query .=' 
    231   GROUP BY tag_id, t.id, t.name, t.url_name'; 
     231  GROUP BY t.id 
     232  ORDER BY '; 
    232233  if ($max_tags>0) 
    233234  { 
    234     $query .= ' 
    235   ORDER BY counter DESC 
     235    $query .= 'counter DESC 
    236236  LIMIT '.$max_tags; 
     237  } 
     238  else 
     239  { 
     240    $query .= 'NULL'; 
    237241  } 
    238242 
Note: See TracChangeset for help on using the changeset viewer.