From 1d3fc9005f00927c19c291f33b5bfffdd81cad6e Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 8 Sep 2011 18:22:27 +0000 Subject: - reoptimize queries for MySql - week starts on monday/sunday applies also to weekly calendar git-svn-id: http://piwigo.org/svn/trunk@12118 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/calendar_monthly.class.php | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'include/calendar_monthly.class.php') diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php index 4b176f85f..2c14088c9 100644 --- a/include/calendar_monthly.class.php +++ b/include/calendar_monthly.class.php @@ -224,15 +224,13 @@ function build_global_calendar(&$tpl_var) assert( count($page['chronology_date']) == 0 ); $query=' -SELECT '.pwg_db_get_date_YYYYMM($this->date_field).' as period,' - .pwg_db_get_year($this->date_field).' as year, ' - .pwg_db_get_month($this->date_field).' as month, - count(distinct id) as count'; +SELECT '.pwg_db_get_date_YYYYMM($this->date_field).' as period, + COUNT(distinct id) as count'; $query.= $this->inner_sql; $query.= $this->get_date_where(); $query.= ' - GROUP BY period, year, month - ORDER BY year DESC, month ASC'; + GROUP BY period + ORDER BY '.pwg_db_get_year($this->date_field).' DESC, '.pwg_db_get_month($this->date_field).' ASC'; $result = pwg_query($query); $items=array(); @@ -368,11 +366,6 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f $items[$day]['width'] = $row['width']; $items[$day]['height'] = $row['height']; $items[$day]['dow'] = $row['dow']; - - if ('sunday' == $conf['week_starts_on']) - { - $items[$day]['dow']++; - } } if ( !empty($items) @@ -389,21 +382,19 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f //first_day_dow = week day corresponding to the first day of this month $wday_labels = $lang['day']; - // BEGIN - pass now in week starting Monday - if ($first_day_dow==0) - { - $first_day_dow = 6; - } - else - { - $first_day_dow -= 1; - } - if ('monday' == $conf['week_starts_on']) { + if ($first_day_dow==0) + { + $first_day_dow = 6; + } + else + { + $first_day_dow -= 1; + } + array_push( $wday_labels, array_shift($wday_labels) ); } - // END - pass now in week starting Monday $cell_width = $conf['calendar_month_cell_width']; $cell_height = $conf['calendar_month_cell_height']; @@ -528,4 +519,4 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f } } -?> +?> \ No newline at end of file -- cgit v1.2.3