Changeset 18455


Ignore:
Timestamp:
Oct 4, 2012, 6:15:28 AM (12 years ago)
Author:
rvelices
Message:

php optimizations:

  • use faster [] operator instead of array_push
  • if tags are grouped by letter, don't add level to tags, sort etc ...
Location:
trunk
Files:
3 edited

Legend:

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

    r12922 r18455  
    6565  while ($row = pwg_db_fetch_assoc($result))
    6666  {
    67     $counter = @$tag_counters[ $row['id'] ];
     67    $counter = intval(@$tag_counters[ $row['id'] ]);
    6868    if ( $counter )
    6969    {
    7070      $row['counter'] = $counter;
    7171      $row['name'] = trigger_event('render_tag_name', $row['name']);
    72       array_push($tags, $row);
     72      $tags[] = $row;
    7373    }
    7474  }
     
    9292  {
    9393    $row['name'] = trigger_event('render_tag_name', $row['name']);
    94     array_push($tags, $row);
     94    $tags[] = $row;
    9595  }
    9696
     
    139139
    140140  // display sorted tags
    141   foreach (array_keys($tags) as $k)
    142   {
    143     $tags[$k]['level'] = 1;
     141  foreach ($tags as &$tag)
     142  {
     143    $tag['level'] = 1;
    144144
    145145    // based on threshold, determine current tag level
    146146    for ($i = $conf['tags_levels'] - 1; $i >= 1; $i--)
    147147    {
    148       if ($tags[$k]['counter'] > $threshold_of_level[$i])
     148      if ($tag['counter'] > $threshold_of_level[$i])
    149149      {
    150         $tags[$k]['level'] = $i + 1;
     150        $tag['level'] = $i + 1;
    151151        break;
    152152      }
    153153    }
    154154  }
     155  unset($tag);
    155156
    156157  return $tags;
     
    255256  {
    256257    $row['name'] = trigger_event('render_tag_name', $row['name']);
    257     array_push($tags, $row);
     258    $tags[] = $row;
    258259  }
    259260  usort($tags, 'tag_alpha_compare');
  • trunk/tags.php

    r18063 r18455  
    160160  }
    161161}
    162 
    163 // +-----------------------------------------------------------------------+
    164 // |                        tag cloud construction                         |
    165 // +-----------------------------------------------------------------------+
    166 
    167 // we want only the first most represented tags, so we sort them by counter
    168 // and take the first tags
    169 usort($tags, 'counter_compare');
    170 $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
    171 
    172 // depending on its counter and the other tags counter, each tag has a level
    173 $tags = add_level_to_tags($tags);
    174 
    175 // we want tags diplayed in alphabetic order
    176 if ('letters' != $page['display_mode'])
    177 {
     162else
     163{
     164  // +-----------------------------------------------------------------------+
     165  // |                        tag cloud construction                         |
     166  // +-----------------------------------------------------------------------+
     167
     168  // we want only the first most represented tags, so we sort them by counter
     169  // and take the first tags
     170  usort($tags, 'counter_compare');
     171  $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
     172
     173  // depending on its counter and the other tags counter, each tag has a level
     174  $tags = add_level_to_tags($tags);
     175
     176  // we want tags diplayed in alphabetic order
    178177  usort($tags, 'tag_alpha_compare');
    179 }
    180 
    181 // display sorted tags
    182 foreach ($tags as $tag)
    183 {
    184   $template->append(
    185     'tags',
    186     array_merge(
    187       $tag,
    188       array(
    189         'URL' => make_index_url(
    190           array(
    191             'tags' => array($tag),
    192             )
    193           ),
     178
     179  // display sorted tags
     180  foreach ($tags as $tag)
     181  {
     182    $template->append(
     183      'tags',
     184      array_merge(
     185        $tag,
     186        array(
     187          'URL' => make_index_url(
     188            array(
     189              'tags' => array($tag),
     190              )
     191            ),
     192          )
    194193        )
    195       )
    196     );
    197 }
    198 
     194      );
     195  }
     196}
    199197// include menubar
    200198$themeconf = $template->get_template_vars('themeconf');
  • trunk/themes/default/template/tags.tpl

    r14240 r18455  
    2020{include file='infos_errors.tpl'}
    2121
    22 {if isset($tags)}
    23         {if $display_mode == 'cloud'}
    24         <div id="fullTagCloud">
    25                 {foreach from=$tags item=tag}
    26                 <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
     22
     23{if $display_mode == 'cloud' and isset($tags)}
     24<div id="fullTagCloud">
     25        {foreach from=$tags item=tag}
     26        <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
     27        {/foreach}
     28</div>
     29{/if}
     30
     31{if $display_mode == 'letters' and isset($letters)}
     32<table>
     33        <tr>
     34                <td valign="top">
     35        {foreach from=$letters item=letter}
     36<fieldset class="tagLetter">
     37        <legend class="tagLetterLegend">{$letter.TITLE}</legend>
     38        <table class="tagLetterContent">
     39                {foreach from=$letter.tags item=tag}
     40                <tr class="tagLine">
     41                        <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
     42                        <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
     43                </tr>
    2744                {/foreach}
    28         </div>
    29         {/if}
    30 
    31   {if $display_mode == 'letters'}
    32   <table>
    33     <tr>
    34       <td valign="top">
    35     {foreach from=$letters item=letter}
    36   <fieldset class="tagLetter">
    37     <legend class="tagLetterLegend">{$letter.TITLE}</legend>
    38     <table class="tagLetterContent">
    39       {foreach from=$letter.tags item=tag}
    40       <tr class="tagLine">
    41         <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
    42         <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
    43       </tr>
    44       {/foreach}
    45     </table>
    46   </fieldset>
    47       {if isset($letter.CHANGE_COLUMN) }
    48       </td>
    49       <td valign="top">
    50       {/if}
    51     {/foreach}
    52       </td>
    53     </tr>
    54   </table>
    55   {/if}
     45        </table>
     46</fieldset>
     47                {if isset($letter.CHANGE_COLUMN) }
     48                </td>
     49                <td valign="top">
     50                {/if}
     51        {/foreach}
     52                </td>
     53        </tr>
     54</table>
    5655{/if}
    5756
Note: See TracChangeset for help on using the changeset viewer.