Changeset 2333 for trunk/admin/stats.php


Ignore:
Timestamp:
May 6, 2008, 3:04:58 AM (17 years ago)
Author:
rvelices
Message:
  • remove some unnecessary db columns (#history_summary.id, #history.year, month, day and hour)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/stats.php

    r2299 r2333  
    116116$query = '
    117117SELECT
    118     year,
    119     month,
    120     day,
    121     hour,
    122     max(id) AS max_id,
     118    date,
     119    HOUR(time) AS hour,
     120    MAX(id) AS max_id,
    123121    COUNT(*) AS nb_pages
    124122  FROM '.HISTORY_TABLE.'
    125123  WHERE summarized = \'false\'
    126124  GROUP BY
    127     year ASC,
    128     month ASC,
    129     day ASC,
    130     hour ASC
     125    date ASC,
     126    HOUR(time) ASC
    131127;';
    132128$result = pwg_query($query);
     
    141137{
    142138  $time_keys = array(
     139    substr($row['date'], 0, 4), //yyyy
     140    substr($row['date'], 0, 7), //yyyy-mm
     141    substr($row['date'], 0, 10),//yyyy-mm-dd
    143142    sprintf(
    144       '%4u',
    145       $row['year']
    146       ),
    147     sprintf(
    148       '%4u.%02u',
    149       $row['year'], $row['month']
    150       ),
    151     sprintf(
    152       '%4u.%02u.%02u',
    153       $row['year'], $row['month'], $row['day']
    154       ),
    155     sprintf(
    156       '%4u.%02u.%02u.%02u',
    157       $row['year'], $row['month'], $row['day'], $row['hour']
     143      '%s-%02u',
     144      $row['date'], $row['hour']
    158145      ),
    159146    );
     
    190177// +---------------+----------+
    191178// | 2005          |   241109 |
    192 // | 2005.08       |    20133 |
    193 // | 2005.08.25    |      620 |
    194 // | 2005.08.25.21 |      151 |
     179// | 2005-08       |    20133 |
     180// | 2005-08-25    |      620 |
     181// | 2005-08-25-21 |      151 |
    195182// +---------------+----------+
    196183
    197 $existing_time_keys = array();
    198 
    199 if (isset($first_time_key))
    200 {
    201   list($year, $month, $day, $hour) = explode('.', $first_time_key);
    202 
    203   $time_keys = array(
    204     sprintf('%4u',                $year),
    205     sprintf('%4u.%02u',           $year, $month),
    206     sprintf('%4u.%02u.%02u',      $year, $month, $day),
    207     sprintf('%4u.%02u.%02u.%02u', $year, $month, $day, $hour),
    208     );
    209 
    210   $query = '
    211 SELECT
    212     id,
    213     nb_pages
    214   FROM '.HISTORY_SUMMARY_TABLE.'
    215   WHERE id IN (\''.implode("', '", $time_keys).'\')
    216 ;';
    217   $result = pwg_query($query);
    218   while ($row = mysql_fetch_array($result))
    219   {
    220     $existing_time_keys[ $row['id'] ] = $row['nb_pages'];
    221   }
    222 }
    223184
    224185$updates = array();
    225186$inserts = array();
    226187
    227 foreach (array_keys($need_update) as $time_key)
    228 {
    229   $time_tokens = explode('.', $time_key);
    230 
    231   if (isset($existing_time_keys[$time_key]))
    232   {
    233     array_push(
    234       $updates,
    235       array(
    236         'id'       => $time_key,
    237         'nb_pages' => $existing_time_keys[$time_key] + $need_update[$time_key],
     188if (isset($first_time_key))
     189{
     190  list($year, $month, $day, $hour) = explode('-', $first_time_key);
     191
     192  $query = '
     193SELECT *
     194  FROM '.HISTORY_SUMMARY_TABLE.'
     195  WHERE year='.$year.'
     196    AND ( month IS NULL
     197      OR ( month='.$month.'
     198        AND ( day is NULL
     199          OR (day='.$day.'
     200            AND (hour IS NULL OR hour='.$hour.')
     201          )
    238202        )
    239       );
    240   }
    241   else
    242   {
    243     array_push(
     203      )
     204    )
     205;';
     206  $result = pwg_query($query);
     207  while ($row = mysql_fetch_assoc($result))
     208  {
     209    $key = sprintf('%4u', $row['year']);
     210    if ( isset($row['month']) )
     211    {
     212      $key .= sprintf('-%02u', $row['month']);
     213      if ( isset($row['day']) )
     214      {
     215        $key .= sprintf('-%02u', $row['day']);
     216        if ( isset($row['hour']) )
     217        {
     218          $key .= sprintf('-%02u', $row['hour']);
     219        }
     220      }
     221    }
     222
     223    if (isset($need_update[$key]))
     224    {
     225      $row['nb_pages'] += $need_update[$key];
     226      array_push($updates, $row);
     227      unset($need_update[$key]);
     228    }
     229  }
     230}
     231
     232foreach ($need_update as $time_key => $nb_pages)
     233{
     234  $time_tokens = explode('-', $time_key);
     235
     236  array_push(
    244237      $inserts,
    245238      array(
    246         'id'       => $time_key,
    247239        'year'     => $time_tokens[0],
    248240        'month'    => @$time_tokens[1],
    249241        'day'      => @$time_tokens[2],
    250242        'hour'     => @$time_tokens[3],
    251         'nb_pages' => $need_update[$time_key],
     243        'nb_pages' => $nb_pages,
    252244        )
    253245      );
    254   }
    255246}
    256247
     
    260251    HISTORY_SUMMARY_TABLE,
    261252    array(
    262       'primary' => array('id'),
     253      'primary' => array('year','month','day','hour'),
    263254      'update'  => array('nb_pages'),
    264255      ),
Note: See TracChangeset for help on using the changeset viewer.