Ignore:
Timestamp:
Nov 21, 2004, 12:13:48 PM (20 years ago)
Author:
plg
Message:

optimization : instead of reading each $confcalendar_datefield for
matching YEAR() and MONTH(), use of SQL statement BETWEEN ... AND ... on the
date field + new index image_i5 on date_creation (default date field for
calendar)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_calendar.inc.php

    r606 r612  
    8787SELECT DISTINCT(MONTH('.$conf['calendar_datefield'].')) AS month
    8888     , COUNT(id) AS count
    89   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    90   '.$page['where'].'
    91     AND id = image_id
    92     AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
     89  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     90  '.$page['where'].'
     91    AND '.$conf['calendar_datefield'].'
     92      BETWEEN \''.$page['calendar_year'].'-1-1\'
     93      AND \''.$page['calendar_year'].'-12-31\'
    9394  GROUP BY MONTH('.$conf['calendar_datefield'].')
    9495;';
     
    158159  $query = '
    159160SELECT DISTINCT('.$conf['calendar_datefield'].') AS day, COUNT(id) AS count
    160   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    161   '.$page['where'].'
    162     AND id = image_id
    163     AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
    164     AND MONTH('.$conf['calendar_datefield'].') = '.$page['calendar_month'].'
     161  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     162  '.$page['where'].'
     163    AND '.$conf['calendar_datefield'].'
     164      BETWEEN \''.$page['calendar_year'].'-'.$page['calendar_month'].'-1\'
     165      AND \''.$page['calendar_year'].'-'.$page['calendar_month'].'-31\'
    165166  GROUP BY day
    166167;';
     
    183184  $query = '
    184185SELECT category_id AS category, COUNT(id) AS count
    185   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
     186  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
    186187  '.$page['where'].'
    187188    AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\'
    188     AND id = image_id
    189189  GROUP BY category_id
    190190;';
     
    221221    $query = '
    222222SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    223   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    224   '.$page['where'].'
    225     AND YEAR('.$conf['calendar_datefield'].') = '.$calendar_year.'
    226     AND id = image_id
     223  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     224  '.$page['where'].'
     225    AND '.$conf['calendar_datefield'].'
     226      BETWEEN \''.$calendar_year.'-1-1\'
     227      AND \''.$calendar_year.'-12-31\'
    227228  ORDER BY RAND()
    228229  LIMIT 0,1
     
    266267    $query = '
    267268SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    268   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
    269   '.$page['where'].'
    270     AND YEAR('.$conf['calendar_datefield'].') = '.$page['calendar_year'].'
    271     AND MONTH('.$conf['calendar_datefield'].') = '.$calendar_month.'
    272     AND id = image_id
     269  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     270  '.$page['where'].'
     271    AND '.$conf['calendar_datefield'].'
     272      BETWEEN \''.$page['calendar_year'].'-'.$calendar_month.'-1\'
     273      AND \''.$page['calendar_year'].'-'.$calendar_month.'-31\'
    273274  ORDER BY RAND()
    274275  LIMIT 0,1
     
    320321    $query = '
    321322SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
    322   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
     323  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
    323324  '.$page['where'].'
    324325    AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\'
    325     AND id = image_id
    326326  ORDER BY RAND()
    327327  LIMIT 0,1
Note: See TracChangeset for help on using the changeset viewer.