mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 03:09:58 +03:00
bug fixed in get_available_tags: do not always use persistent_cache
... also optimize tag name fetching
This commit is contained in:
parent
0cf2a57357
commit
542910cb6d
1 changed files with 23 additions and 6 deletions
|
@ -41,6 +41,8 @@ function get_available_tags($tag_ids=array())
|
||||||
{
|
{
|
||||||
global $persistent_cache, $user;
|
global $persistent_cache, $user;
|
||||||
|
|
||||||
|
$use_persistent_cache = true;
|
||||||
|
|
||||||
// we can find top fatter tags among reachable images
|
// we can find top fatter tags among reachable images
|
||||||
$query = '
|
$query = '
|
||||||
SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
|
@ -59,6 +61,8 @@ SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
|
|
||||||
if (is_array($tag_ids) and count($tag_ids) > 0)
|
if (is_array($tag_ids) and count($tag_ids) > 0)
|
||||||
{
|
{
|
||||||
|
$use_persistent_cache = false;
|
||||||
|
|
||||||
$query .= '
|
$query .= '
|
||||||
AND tag_id IN ('.implode(',', $tag_ids).')
|
AND tag_id IN ('.implode(',', $tag_ids).')
|
||||||
';
|
';
|
||||||
|
@ -68,11 +72,18 @@ SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
GROUP BY tag_id
|
GROUP BY tag_id
|
||||||
;';
|
;';
|
||||||
|
|
||||||
$cache_key = $persistent_cache->make_key(__FUNCTION__.$user['id'].$user['cache_update_time']);
|
if ($use_persistent_cache)
|
||||||
if (!$persistent_cache->get($cache_key, $tag_counters))
|
{
|
||||||
|
$cache_key = $persistent_cache->make_key(__FUNCTION__.$user['id'].$user['cache_update_time']);
|
||||||
|
if (!$persistent_cache->get($cache_key, $tag_counters))
|
||||||
|
{
|
||||||
|
$tag_counters = query2array($query, 'tag_id', 'counter');
|
||||||
|
$persistent_cache->set($cache_key, $tag_counters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$tag_counters = query2array($query, 'tag_id', 'counter');
|
$tag_counters = query2array($query, 'tag_id', 'counter');
|
||||||
$persistent_cache->set($cache_key, $tag_counters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty($tag_counters) )
|
if ( empty($tag_counters) )
|
||||||
|
@ -83,15 +94,21 @@ SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
$query = '
|
$query = '
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM '.TAGS_TABLE;
|
FROM '.TAGS_TABLE;
|
||||||
|
|
||||||
|
if (count($tag_counters) < 1000)
|
||||||
|
{
|
||||||
|
$query .= '
|
||||||
|
WHERE id IN ('.implode(',', array_keys($tag_counters)).')
|
||||||
|
';
|
||||||
|
}
|
||||||
$result = pwg_query($query);
|
$result = pwg_query($query);
|
||||||
|
|
||||||
$tags = array();
|
$tags = array();
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
$counter = intval(@$tag_counters[ $row['id'] ]);
|
if (isset($tag_counters[ $row['id'] ]))
|
||||||
if ( $counter )
|
|
||||||
{
|
{
|
||||||
$row['counter'] = $counter;
|
$row['counter'] = intval($tag_counters[ $row['id'] ]);
|
||||||
$row['name'] = trigger_change('render_tag_name', $row['name'], $row);
|
$row['name'] = trigger_change('render_tag_name', $row['name'], $row);
|
||||||
$tags[] = $row;
|
$tags[] = $row;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue