Faster tag list
This commit is contained in:
parent
fe99f97287
commit
c3b2c68add
4 changed files with 6 additions and 23 deletions
|
@ -12,12 +12,12 @@ class TagController
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
||||||
$suppliedFilter = InputHelper::get('filter');
|
$suppliedFilter = InputHelper::get('filter');
|
||||||
|
|
||||||
$tags = Model_Tag::getEntities($suppliedFilter, null, null);
|
$tags = Model_Tag::getEntitiesRows($suppliedFilter, null, null);
|
||||||
$this->context->transport->tags = $tags;
|
$this->context->transport->tags = $tags;
|
||||||
|
|
||||||
if ($this->context->json)
|
if ($this->context->json)
|
||||||
$this->context->transport->tags = array_values(array_map(function($tag) {
|
$this->context->transport->tags = array_values(array_map(function($tag) {
|
||||||
return ['name' => $tag->name, 'count' => $tag->getPostCount()];
|
return ['name' => $tag['name'], 'count' => $tag['post_count']];
|
||||||
}, $this->context->transport->tags));
|
}, $this->context->transport->tags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,21 +83,4 @@ class Model_Tag extends AbstractModel
|
||||||
{
|
{
|
||||||
return 'Model_Tag_Querybuilder';
|
return 'Model_Tag_Querybuilder';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEntities($query, $perPage = null, $page = 1)
|
|
||||||
{
|
|
||||||
$table = static::getTableName();
|
|
||||||
$rows = self::getEntitiesRows($query, $perPage, $page);
|
|
||||||
$entities = R::convertToBeans($table, $rows);
|
|
||||||
|
|
||||||
$rowMap = [];
|
|
||||||
foreach ($rows as &$row)
|
|
||||||
$rowMap[$row['id']] = $row;
|
|
||||||
unset ($row);
|
|
||||||
|
|
||||||
foreach ($entities as $entity)
|
|
||||||
$entity->setMeta('post_count', $rowMap[$entity->id]['count']);
|
|
||||||
|
|
||||||
return $entities;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ class model_Tag_QueryBuilder implements AbstractQueryBuilder
|
||||||
$limitQuery = false;
|
$limitQuery = false;
|
||||||
$dbQuery
|
$dbQuery
|
||||||
->addSql(', COUNT(post_tag.post_id)')
|
->addSql(', COUNT(post_tag.post_id)')
|
||||||
->as('count')
|
->as('post_count')
|
||||||
->from('tag')
|
->from('tag')
|
||||||
->innerJoin('post_tag')
|
->innerJoin('post_tag')
|
||||||
->on('tag.id = post_tag.tag_id')
|
->on('tag.id = post_tag.tag_id')
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<?php $max = max([0]+array_map(function($x) { return $x->getPostCount(); }, $this->context->transport->tags)); ?>
|
<?php $max = max([0]+array_map(function($x) { return $x['post_count']; }, $this->context->transport->tags)); ?>
|
||||||
<?php $add = 0.25 ?>
|
<?php $add = 0.25 ?>
|
||||||
<?php $mul = 0.75 / max(1, log(max(1, $max))) ?>
|
<?php $mul = 0.75 / max(1, log(max(1, $max))) ?>
|
||||||
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '{query}']) ?>
|
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '{query}']) ?>
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach ($this->context->transport->tags as $tag): ?>
|
<?php foreach ($this->context->transport->tags as $tag): ?>
|
||||||
<?php $name = $tag->name ?>
|
<?php $name = $tag['name'] ?>
|
||||||
<?php $count = $tag->getPostCount() ?>
|
<?php $count = $tag['post_count'] ?>
|
||||||
<li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)">
|
<li class="tag" title="<?php echo $name ?> (<?php echo $count ?>)">
|
||||||
<a href="<?php echo TextHelper::replaceTokens($url, ['query' => $name]) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
|
<a href="<?php echo TextHelper::replaceTokens($url, ['query' => $name]) ?>" style="opacity: <?php printf('%.02f', $add + $mul * log($count)) ?>">
|
||||||
<?php echo $name . ' (' . $count . ')' ?>
|
<?php echo $name . ' (' . $count . ')' ?>
|
||||||
|
|
Loading…
Reference in a new issue