Skip to content

Commit 0a335f9

Browse files
author
epriestley
committed
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
1 parent c96e17f commit 0a335f9

8 files changed

+41
-71
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_participant
2+
DROP participationStatus;

src/__phutil_library_map__.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@
305305
'ConpherenceParticipantCountQuery' => 'applications/conpherence/query/ConpherenceParticipantCountQuery.php',
306306
'ConpherenceParticipantQuery' => 'applications/conpherence/query/ConpherenceParticipantQuery.php',
307307
'ConpherenceParticipantView' => 'applications/conpherence/view/ConpherenceParticipantView.php',
308-
'ConpherenceParticipationStatus' => 'applications/conpherence/constants/ConpherenceParticipationStatus.php',
309308
'ConpherenceQueryThreadConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryThreadConduitAPIMethod.php',
310309
'ConpherenceQueryTransactionConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryTransactionConduitAPIMethod.php',
311310
'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php',
@@ -5099,7 +5098,6 @@
50995098
'ConpherenceParticipantCountQuery' => 'PhabricatorOffsetPagedQuery',
51005099
'ConpherenceParticipantQuery' => 'PhabricatorOffsetPagedQuery',
51015100
'ConpherenceParticipantView' => 'AphrontView',
5102-
'ConpherenceParticipationStatus' => 'ConpherenceConstants',
51035101
'ConpherenceQueryThreadConduitAPIMethod' => 'ConpherenceConduitAPIMethod',
51045102
'ConpherenceQueryTransactionConduitAPIMethod' => 'ConpherenceConduitAPIMethod',
51055103
'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',

src/applications/conpherence/constants/ConpherenceParticipationStatus.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/applications/conpherence/controller/ConpherenceNotificationPanelController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public function handleRequest(AphrontRequest $request) {
77
$user = $request->getUser();
88
$conpherences = array();
99
require_celerity_resource('conpherence-notification-css');
10-
$unread_status = ConpherenceParticipationStatus::BEHIND;
1110

1211
$participant_data = id(new ConpherenceParticipantQuery())
1312
->withParticipantPHIDs(array($user->getPHID()))
@@ -37,7 +36,7 @@ public function handleRequest(AphrontRequest $request) {
3736
'conpherence-notification',
3837
);
3938

40-
if ($p_data->getParticipationStatus() == $unread_status) {
39+
if (!$p_data->isUpToDate($conpherence)) {
4140
$classes[] = 'phabricator-notification-unread';
4241
}
4342
$uri = $this->getApplicationURI($conpherence->getID().'/');
@@ -95,7 +94,7 @@ public function handleRequest(AphrontRequest $request) {
9594

9695
$unread = id(new ConpherenceParticipantCountQuery())
9796
->withParticipantPHIDs(array($user->getPHID()))
98-
->withParticipationStatus($unread_status)
97+
->withUnread(true)
9998
->execute();
10099
$unread_count = idx($unread, $user->getPHID(), 0);
101100

src/applications/conpherence/editor/ConpherenceEditor.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,14 @@ protected function applyInitialEffects(
173173
$phids = $this->getPHIDTransactionNewValue($xaction, array());
174174
foreach ($phids as $phid) {
175175
if ($phid == $this->getActor()->getPHID()) {
176-
$status = ConpherenceParticipationStatus::UP_TO_DATE;
177176
$message_count = 1;
178177
} else {
179-
$status = ConpherenceParticipationStatus::BEHIND;
180178
$message_count = 0;
181179
}
182180
$participants[$phid] =
183181
id(new ConpherenceParticipant())
184182
->setConpherencePHID($object->getPHID())
185183
->setParticipantPHID($phid)
186-
->setParticipationStatus($status)
187184
->setDateTouched(time())
188185
->setSeenMessageCount($message_count)
189186
->save();
@@ -243,17 +240,14 @@ protected function applyCustomExternalTransaction(
243240
$add = array_keys(array_diff_key($new_map, $old_map));
244241
foreach ($add as $phid) {
245242
if ($phid == $this->getActor()->getPHID()) {
246-
$status = ConpherenceParticipationStatus::UP_TO_DATE;
247243
$message_count = $object->getMessageCount();
248244
} else {
249-
$status = ConpherenceParticipationStatus::BEHIND;
250245
$message_count = 0;
251246
}
252247
$participants[$phid] =
253248
id(new ConpherenceParticipant())
254249
->setConpherencePHID($object->getPHID())
255250
->setParticipantPHID($phid)
256-
->setParticipationStatus($status)
257251
->setDateTouched(time())
258252
->setSeenMessageCount($message_count)
259253
->save();
@@ -279,22 +273,18 @@ protected function applyFinalEffects(
279273

280274
// update everyone's participation status on a message -only-
281275
$xaction_phid = $xaction->getPHID();
282-
$behind = ConpherenceParticipationStatus::BEHIND;
283-
$up_to_date = ConpherenceParticipationStatus::UP_TO_DATE;
284276
$participants = $object->getParticipants();
285277
$user = $this->getActor();
286278
$time = time();
287279
foreach ($participants as $phid => $participant) {
288280
if ($phid != $user->getPHID()) {
289-
if ($participant->getParticipationStatus() != $behind) {
281+
if ($participant->isUpToDate($object)) {
290282
$participant->setSeenMessageCount(
291283
$object->getMessageCount() - $message_count);
292284
}
293-
$participant->setParticipationStatus($behind);
294285
$participant->setDateTouched($time);
295286
} else {
296287
$participant->setSeenMessageCount($object->getMessageCount());
297-
$participant->setParticipationStatus($up_to_date);
298288
$participant->setDateTouched($time);
299289
}
300290
$participant->save();
Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,69 @@
11
<?php
22

3-
/**
4-
* Query class that answers the question:
5-
*
6-
* - Q: How many unread conpherences am I participating in?
7-
* - A:
8-
* id(new ConpherenceParticipantCountQuery())
9-
* ->withParticipantPHIDs(array($my_phid))
10-
* ->withParticipationStatus(ConpherenceParticipationStatus::BEHIND)
11-
* ->execute();
12-
*/
133
final class ConpherenceParticipantCountQuery
144
extends PhabricatorOffsetPagedQuery {
155

166
private $participantPHIDs;
17-
private $participationStatus;
7+
private $unread;
188

199
public function withParticipantPHIDs(array $phids) {
2010
$this->participantPHIDs = $phids;
2111
return $this;
2212
}
2313

24-
public function withParticipationStatus($participation_status) {
25-
$this->participationStatus = $participation_status;
14+
public function withUnread($unread) {
15+
$this->unread = $unread;
2616
return $this;
2717
}
2818

2919
public function execute() {
20+
$thread = new ConpherenceThread();
3021
$table = new ConpherenceParticipant();
31-
$conn_r = $table->establishConnection('r');
22+
$conn = $table->establishConnection('r');
3223

3324
$rows = queryfx_all(
34-
$conn_r,
35-
'SELECT COUNT(*) as count, participantPHID '.
36-
'FROM %T participant %Q %Q %Q',
25+
$conn,
26+
'SELECT COUNT(*) as count, participantPHID
27+
FROM %T participant JOIN %T thread
28+
ON participant.conpherencePHID = thread.phid %Q %Q %Q',
3729
$table->getTableName(),
38-
$this->buildWhereClause($conn_r),
39-
$this->buildGroupByClause($conn_r),
40-
$this->buildLimitClause($conn_r));
30+
$thread->getTableName(),
31+
$this->buildWhereClause($conn),
32+
$this->buildGroupByClause($conn),
33+
$this->buildLimitClause($conn));
4134

4235
return ipull($rows, 'count', 'participantPHID');
4336
}
4437

45-
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
38+
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
4639
$where = array();
4740

48-
if ($this->participantPHIDs) {
41+
if ($this->participantPHIDs !== null) {
4942
$where[] = qsprintf(
50-
$conn_r,
51-
'participantPHID IN (%Ls)',
43+
$conn,
44+
'participant.participantPHID IN (%Ls)',
5245
$this->participantPHIDs);
5346
}
5447

55-
if ($this->participationStatus !== null) {
56-
$where[] = qsprintf(
57-
$conn_r,
58-
'participationStatus = %d',
59-
$this->participationStatus);
48+
if ($this->unread !== null) {
49+
if ($this->unread) {
50+
$where[] = qsprintf(
51+
$conn,
52+
'participant.seenMessageCount < thread.messageCount');
53+
} else {
54+
$where[] = qsprintf(
55+
$conn,
56+
'participant.seenMessageCount >= thread.messageCount');
57+
}
6058
}
6159

6260
return $this->formatWhereClause($where);
6361
}
6462

65-
private function buildGroupByClause(AphrontDatabaseConnection $conn_r) {
66-
$group_by = qsprintf(
67-
$conn_r,
63+
private function buildGroupByClause(AphrontDatabaseConnection $conn) {
64+
return qsprintf(
65+
$conn,
6866
'GROUP BY participantPHID');
69-
70-
return $group_by;
7167
}
7268

7369
}

src/applications/conpherence/storage/ConpherenceParticipant.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ final class ConpherenceParticipant extends ConpherenceDAO {
44

55
protected $participantPHID;
66
protected $conpherencePHID;
7-
protected $participationStatus;
87
protected $seenMessageCount;
98
protected $dateTouched;
109
protected $settings = array();
@@ -15,7 +14,6 @@ protected function getConfiguration() {
1514
'settings' => self::SERIALIZATION_JSON,
1615
),
1716
self::CONFIG_COLUMN_SCHEMA => array(
18-
'participationStatus' => 'uint32',
1917
'dateTouched' => 'epoch',
2018
'seenMessageCount' => 'uint64',
2119
),
@@ -24,12 +22,12 @@ protected function getConfiguration() {
2422
'columns' => array('conpherencePHID', 'participantPHID'),
2523
'unique' => true,
2624
),
27-
'unreadCount' => array(
28-
'columns' => array('participantPHID', 'participationStatus'),
29-
),
3025
'participationIndex' => array(
3126
'columns' => array('participantPHID', 'dateTouched', 'id'),
3227
),
28+
'key_thread' => array(
29+
'columns' => array('participantPHID', 'conpherencePHID'),
30+
),
3331
),
3432
) + parent::getConfiguration();
3533
}
@@ -41,8 +39,8 @@ public function getSettings() {
4139
public function markUpToDate(
4240
ConpherenceThread $conpherence,
4341
ConpherenceTransaction $xaction) {
42+
4443
if (!$this->isUpToDate($conpherence)) {
45-
$this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE);
4644
$this->setSeenMessageCount($conpherence->getMessageCount());
4745
$this->save();
4846

@@ -55,11 +53,7 @@ public function markUpToDate(
5553
}
5654

5755
public function isUpToDate(ConpherenceThread $conpherence) {
58-
return
59-
($this->getSeenMessageCount() == $conpherence->getMessageCount())
60-
&&
61-
($this->getParticipationStatus() ==
62-
ConpherenceParticipationStatus::UP_TO_DATE);
56+
return ($this->getSeenMessageCount() == $conpherence->getMessageCount());
6357
}
6458

6559
}

src/applications/people/cache/PhabricatorUserMessageCountCacheType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ public function newValueForUsers($key, array $users) {
2828

2929
$user_phids = mpull($users, 'getPHID');
3030

31-
$unread_status = ConpherenceParticipationStatus::BEHIND;
3231
$unread = id(new ConpherenceParticipantCountQuery())
3332
->withParticipantPHIDs($user_phids)
34-
->withParticipationStatus($unread_status)
33+
->withUnread(true)
3534
->execute();
3635

3736
$empty = array_fill_keys($user_phids, 0);

0 commit comments

Comments
 (0)