Skip to content

Commit

Permalink
createTagCondition 速度改善 (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
seto1 committed Apr 11, 2024
1 parent 8932d2b commit 8c7e86b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/Baser/Plugin/Blog/Model/BlogPost.php
Expand Up @@ -1016,16 +1016,33 @@ public function createTagCondition($conditions, $tag)
if (!is_array($tag)) {
$tag = [$tag];
}
foreach($tag as $key => $value) {
foreach ($tag as $key => $value) {
$tag[$key] = urldecode($value);
}
$tags = $this->BlogTag->find('all', [
'conditions' => ['BlogTag.name' => $tag],
'recursive' => 1,

$tagIds = $this->BlogTag->find('list', [
'fields' => ['id'],
'conditions' => [
'name' => $tag
],
'recursive' => -1,
'cache' => false,
]);
if (!$tagIds) {
$conditions['BlogPost.id'] = null;
return $conditions;
}

$postIds = $this->BlogPostsBlogTag->find('list', [
'fields' => ['blog_post_id'],
'conditions' => [
'blog_tag_id' => $tagIds
],
'recursive' => -1,
'cache' => false,
]);
if (isset($tags[0]['BlogPost'][0]['id'])) {
$conditions['BlogPost.id'] = Hash::extract($tags, '{n}.BlogPost.{n}.id');
if ($postIds) {
$conditions['BlogPost.id'] = $postIds;
} else {
$conditions['BlogPost.id'] = null;
}
Expand Down

0 comments on commit 8c7e86b

Please sign in to comment.