Skip to content

Commit

Permalink
Remove redundant query criteria in ThreadManager
Browse files Browse the repository at this point in the history
The elemMatch() criteria already covers participants.$id, since metadata exists for each participant. Removing this extra criteria will allow us to focus on using the metadata indexes.

Also left a TODO regarding the unindexable keywords query.
  • Loading branch information
jmikola committed Dec 13, 2011
1 parent 351c458 commit 2928424
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions DocumentManager/ThreadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ public function getParticipantInboxThreadsQueryBuilder(ParticipantInterface $par

// TODO: sort by date of last message written by an other participant
return $queryBuilder
// the participant is in the thread participants
->field('participants.$id')->equals(new \MongoId($participant->getId()))
// the thread does not contain spam or flood
->field('isSpam')->equals(false)
// the participant hasn't deleted the thread, and another user wrote a message
->field('metadata')->elemMatch($this
->getNotDeletedByParticipantExpression($queryBuilder, $participant)
->field('lastMessageDate')->notEqual(null)
);
)
// the thread does not contain spam or flood
->field('isSpam')->equals(false);
}

/**
Expand Down Expand Up @@ -124,8 +122,6 @@ public function getParticipantSentThreadsQueryBuilder(ParticipantInterface $part

// TODO: sort by date of last message written by this participant
return $queryBuilder
// the participant is in the thread participants
->field('participants.$id')->equals(new \MongoId($participant->getId()))
// the participant hasn't deleted the thread, and has written a message
->field('metadata')->elemMatch($this
->getNotDeletedByParticipantExpression($queryBuilder, $participant)
Expand Down Expand Up @@ -167,10 +163,9 @@ public function getParticipantThreadsBySearchQueryBuilder(ParticipantInterface $

// TODO: sort by date of last message written by an other participant
return $queryBuilder
// the participant is in the thread participants
->field('participants.$id')->equals(new \MongoId($participant->getId()))
// the thread is not deleted by this participant
->field('metadata')->elemMatch($this->getNotDeletedByParticipantExpression($queryBuilder, $participant))
// TODO: this search is not anchored and uses no indexes
->field('keywords')->equals(new \MongoRegex($regex));
}

Expand Down

0 comments on commit 2928424

Please sign in to comment.