1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-24 13:38:19 +01:00
phorge-phorge/src/applications/conpherence/query/ConpherenceParticipantCountQuery.php
epriestley 0a335f91cd Remove "participationStatus" from ConpherenceParticipant
Summary:
Pathway to D17685. This column is a very complicated cache of: is participant.messageCount equal to thread.messageCount?

We can just ask this question with a JOIN instead and simplify things dramatically.

Test Plan:
  - Ran migration.
  - Browsed around.
  - Sent a message, saw unread count go up.
  - Read the message, saw unread count go down.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D17730
2017-04-19 13:58:42 -07:00

69 lines
1.7 KiB
PHP

<?php
final class ConpherenceParticipantCountQuery
extends PhabricatorOffsetPagedQuery {
private $participantPHIDs;
private $unread;
public function withParticipantPHIDs(array $phids) {
$this->participantPHIDs = $phids;
return $this;
}
public function withUnread($unread) {
$this->unread = $unread;
return $this;
}
public function execute() {
$thread = new ConpherenceThread();
$table = new ConpherenceParticipant();
$conn = $table->establishConnection('r');
$rows = queryfx_all(
$conn,
'SELECT COUNT(*) as count, participantPHID
FROM %T participant JOIN %T thread
ON participant.conpherencePHID = thread.phid %Q %Q %Q',
$table->getTableName(),
$thread->getTableName(),
$this->buildWhereClause($conn),
$this->buildGroupByClause($conn),
$this->buildLimitClause($conn));
return ipull($rows, 'count', 'participantPHID');
}
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array();
if ($this->participantPHIDs !== null) {
$where[] = qsprintf(
$conn,
'participant.participantPHID IN (%Ls)',
$this->participantPHIDs);
}
if ($this->unread !== null) {
if ($this->unread) {
$where[] = qsprintf(
$conn,
'participant.seenMessageCount < thread.messageCount');
} else {
$where[] = qsprintf(
$conn,
'participant.seenMessageCount >= thread.messageCount');
}
}
return $this->formatWhereClause($where);
}
private function buildGroupByClause(AphrontDatabaseConnection $conn) {
return qsprintf(
$conn,
'GROUP BY participantPHID');
}
}