Changes filters from in array to in subqueries

Fixes #3280
This commit is contained in:
Rafael de Camargo 2019-08-25 01:49:52 -03:00 committed by Frédéric Guillot
parent 4d07628054
commit 51b3d811e1
4 changed files with 17 additions and 45 deletions

View File

@ -55,13 +55,7 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface
*/
public function apply()
{
$task_ids = $this->getTaskIdsWithGivenComment();
if (empty($task_ids)) {
$task_ids = array(-1);
}
$this->query->in(TaskModel::TABLE.'.id', $task_ids);
$this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery());
return $this;
}
@ -72,11 +66,11 @@ class TaskCommentFilter extends BaseFilter implements FilterInterface
* @access public
* @return array
*/
protected function getTaskIdsWithGivenComment()
protected function getSubQuery()
{
return $this->db
->table(CommentModel::TABLE)
->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%')
->findAllByColumn(CommentModel::TABLE.'.task_id');
->columns(CommentModel::TABLE.'.task_id')
->ilike(CommentModel::TABLE.'.comment', '%'.$this->value.'%');
}
}

View File

@ -57,13 +57,7 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface
*/
public function apply()
{
$task_ids = $this->getSubQuery()->findAllByColumn('task_id');
if (! empty($task_ids)) {
$this->query->in(TaskModel::TABLE.'.id', $task_ids);
} else {
$this->query->eq(TaskModel::TABLE.'.id', 0); // No match
}
$this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery());
}
/**
@ -76,8 +70,7 @@ class TaskLinkFilter extends BaseFilter implements FilterInterface
{
return $this->db->table(TaskLinkModel::TABLE)
->columns(
TaskLinkModel::TABLE.'.task_id',
LinkModel::TABLE.'.label'
TaskLinkModel::TABLE.'.task_id'
)
->join(LinkModel::TABLE, 'id', 'link_id', TaskLinkModel::TABLE)
->ilike(LinkModel::TABLE.'.label', $this->value);

View File

@ -78,13 +78,7 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface
*/
public function apply()
{
$task_ids = $this->getSubQuery()->findAllByColumn('task_id');
if (! empty($task_ids)) {
$this->query->in(TaskModel::TABLE.'.id', $task_ids);
} else {
$this->query->eq(TaskModel::TABLE.'.id', 0); // No match
}
$this->query->inSubquery(TaskModel::TABLE.'.id', $this->getSubQuery());
}
/**
@ -96,12 +90,7 @@ class TaskSubtaskAssigneeFilter extends BaseFilter implements FilterInterface
protected function getSubQuery()
{
$subquery = $this->db->table(SubtaskModel::TABLE)
->columns(
SubtaskModel::TABLE.'.user_id',
SubtaskModel::TABLE.'.task_id',
UserModel::TABLE.'.name',
UserModel::TABLE.'.username'
)
->columns(SubtaskModel::TABLE.'.task_id')
->join(UserModel::TABLE, 'id', 'user_id', SubtaskModel::TABLE)
->neq(SubtaskModel::TABLE.'.status', SubtaskModel::STATUS_DONE);

View File

@ -57,37 +57,33 @@ class TaskTagFilter extends BaseFilter implements FilterInterface
public function apply()
{
if ($this->value === 'none') {
$task_ids = $this->getTaskIdsWithoutTags();
$sub_query = $this->getQueryOfTaskIdsWithoutTags();
} else {
$task_ids = $this->getTaskIdsWithGivenTag();
$sub_query = $this->getQueryOfTaskIdsWithGivenTag();
}
if (empty($task_ids)) {
$task_ids = array(-1);
}
$this->query->in(TaskModel::TABLE.'.id', $task_ids);
$this->query->inSubquery(TaskModel::TABLE.'.id', $sub_query);
return $this;
}
protected function getTaskIdsWithoutTags()
protected function getQueryOfTaskIdsWithoutTags()
{
return $this->db
->table(TaskModel::TABLE)
->columns(TaskModel::TABLE . '.id')
->asc(TaskModel::TABLE . '.project_id')
->left(TaskTagModel::TABLE, 'tg', 'task_id', TaskModel::TABLE, 'id')
->isNull('tg.tag_id')
->findAllByColumn(TaskModel::TABLE . '.id');
->isNull('tg.tag_id');
}
protected function getTaskIdsWithGivenTag()
protected function getQueryOfTaskIdsWithGivenTag()
{
return $this->db
->table(TagModel::TABLE)
->columns(TaskTagModel::TABLE.'.task_id')
->ilike(TagModel::TABLE.'.name', $this->value)
->asc(TagModel::TABLE.'.project_id')
->join(TaskTagModel::TABLE, 'tag_id', 'id')
->findAllByColumn(TaskTagModel::TABLE.'.task_id');
->join(TaskTagModel::TABLE, 'tag_id', 'id');
}
}