mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Conpherence - get back-end prepped for loading less transactions all the time
Summary: this just does the back-end migration. I realized that we don't need to keep track of cacheTitle and cachePhoto since those are based off recent participation handles and dynamic relative to who is viewing it. Also kept the "last seen phid" as I think that will be useful to have auto-scroll to where you last read. Ref T2867. Test Plan: did the migration. observed sensical values in the database. created a new conpherence - again sensical values. updated a conpherence - more sensical values. Reviewers: epriestley, chad Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T2867 Differential Revision: https://secure.phabricator.com/D5567
This commit is contained in:
parent
a56846e62a
commit
754705df4e
8 changed files with 132 additions and 6 deletions
6
resources/sql/patches/20130403.conpherencecache.sql
Normal file
6
resources/sql/patches/20130403.conpherencecache.sql
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread
|
||||||
|
ADD recentParticipantPHIDs LONGTEXT NOT NULL COLLATE utf8_bin AFTER title,
|
||||||
|
ADD messageCount BIGINT UNSIGNED NOT NULL AFTER title;
|
||||||
|
|
||||||
|
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_participant
|
||||||
|
ADD seenMessageCount BIGINT UNSIGNED NOT NULL AFTER behindTransactionPHID;
|
64
resources/sql/patches/20130403.conpherencecachemig.php
Normal file
64
resources/sql/patches/20130403.conpherencecachemig.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo "Migrating data from conpherence transactions to conpherence 'cache'...\n";
|
||||||
|
|
||||||
|
$table = new ConpherenceThread();
|
||||||
|
$table->openTransaction();
|
||||||
|
$conn_w = $table->establishConnection('w');
|
||||||
|
|
||||||
|
$participant_table = new ConpherenceParticipant();
|
||||||
|
|
||||||
|
$conpherences = new LiskMigrationIterator($table);
|
||||||
|
foreach ($conpherences as $conpherence) {
|
||||||
|
echo 'Migrating conpherence #'.$conpherence->getID()."\n";
|
||||||
|
|
||||||
|
$participants = id(new ConpherenceParticipant())
|
||||||
|
->loadAllWhere('conpherencePHID = %s', $conpherence->getPHID());
|
||||||
|
|
||||||
|
$transactions = id(new ConpherenceTransaction())
|
||||||
|
->loadAllWhere('objectPHID = %s', $conpherence->getPHID());
|
||||||
|
|
||||||
|
$participation_hash = mgroup($participants, 'getBehindTransactionPHID');
|
||||||
|
|
||||||
|
$message_count = 0;
|
||||||
|
$participants_to_cache = array();
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$participants_to_cache[] = $transaction->getAuthorPHID();
|
||||||
|
if ($transaction->getTransactionType() ==
|
||||||
|
PhabricatorTransactions::TYPE_COMMENT) {
|
||||||
|
$message_count++;
|
||||||
|
}
|
||||||
|
$participants_to_update = idx(
|
||||||
|
$participation_hash,
|
||||||
|
$transaction->getPHID(),
|
||||||
|
array());
|
||||||
|
if ($participants_to_update) {
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'UPDATE %T SET seenMessageCount = %d '.
|
||||||
|
'WHERE conpherencePHID = %s AND participantPHID IN (%Ls)',
|
||||||
|
$participant_table->getTableName(),
|
||||||
|
$message_count,
|
||||||
|
$conpherence->getPHID(),
|
||||||
|
mpull($participants_to_update, 'getParticipantPHID'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$participants_to_cache = array_slice(
|
||||||
|
array_unique(array_reverse($participants_to_cache)),
|
||||||
|
0,
|
||||||
|
10);
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'UPDATE %T '.
|
||||||
|
'SET recentParticipantPHIDs = %s, '.
|
||||||
|
'messageCount = %d '.
|
||||||
|
'WHERE phid = %s',
|
||||||
|
$table->getTableName(),
|
||||||
|
json_encode($participants_to_cache),
|
||||||
|
$message_count,
|
||||||
|
$conpherence->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->saveTransaction();
|
||||||
|
echo "\nDone.\n";
|
|
@ -11,7 +11,8 @@ final class ConpherenceNewController extends ConpherenceController {
|
||||||
|
|
||||||
$conpherence = id(new ConpherenceThread())
|
$conpherence = id(new ConpherenceThread())
|
||||||
->attachParticipants(array())
|
->attachParticipants(array())
|
||||||
->attachFilePHIDs(array());
|
->attachFilePHIDs(array())
|
||||||
|
->setMessageCount(0);
|
||||||
$title = pht('New Conversation');
|
$title = pht('New Conversation');
|
||||||
$participants = array();
|
$participants = array();
|
||||||
$message = '';
|
$message = '';
|
||||||
|
@ -34,6 +35,8 @@ final class ConpherenceNewController extends ConpherenceController {
|
||||||
} else {
|
} else {
|
||||||
$participants[] = $user->getPHID();
|
$participants[] = $user->getPHID();
|
||||||
$participants = array_unique($participants);
|
$participants = array_unique($participants);
|
||||||
|
$conpherence->setRecentParticipantPHIDs(
|
||||||
|
array_slice($participants, 0, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = $request->getStr('message');
|
$message = $request->getStr('message');
|
||||||
|
|
|
@ -49,7 +49,7 @@ final class ConpherenceViewController extends
|
||||||
$transactions = $conpherence->getTransactions();
|
$transactions = $conpherence->getTransactions();
|
||||||
$latest_transaction = end($transactions);
|
$latest_transaction = end($transactions);
|
||||||
$write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
|
$write_guard = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
$participant->markUpToDate($latest_transaction);
|
$participant->markUpToDate($conpherence, $latest_transaction);
|
||||||
unset($write_guard);
|
unset($write_guard);
|
||||||
|
|
||||||
$header = $this->renderHeaderPaneContent();
|
$header = $this->renderHeaderPaneContent();
|
||||||
|
|
|
@ -86,11 +86,32 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function applyCustomInternalTransaction(
|
/**
|
||||||
|
* We really only need a read lock if we have a comment. In that case, we
|
||||||
|
* must update the messagesCount field on the conpherence and
|
||||||
|
* seenMessagesCount(s) for the participant(s).
|
||||||
|
*/
|
||||||
|
protected function shouldReadLock(
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
|
$lock = false;
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_COMMENT:
|
||||||
|
$lock = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function applyCustomInternalTransaction(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
switch ($xaction->getTransactionType()) {
|
||||||
|
case PhabricatorTransactions::TYPE_COMMENT:
|
||||||
|
$object->setMessageCount((int)$object->getMessageCount() + 1);
|
||||||
|
break;
|
||||||
case ConpherenceTransactionType::TYPE_TITLE:
|
case ConpherenceTransactionType::TYPE_TITLE:
|
||||||
$object->setTitle($xaction->getNewValue());
|
$object->setTitle($xaction->getNewValue());
|
||||||
break;
|
break;
|
||||||
|
@ -105,6 +126,18 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
ConpherenceImageData::SIZE_HEAD);
|
ConpherenceImageData::SIZE_HEAD);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
$this->updateRecentParticipantPHIDs($object, $xaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateRecentParticipantPHIDs(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
|
$participants = $object->getRecentParticipantPHIDs();
|
||||||
|
array_unshift($participants, $xaction->getAuthorPHID());
|
||||||
|
$participants = array_slice(array_unique($participants), 0, 10);
|
||||||
|
|
||||||
|
$object->setRecentParticipantPHIDs($participants);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,10 +181,13 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
if ($phid != $user->getPHID()) {
|
if ($phid != $user->getPHID()) {
|
||||||
if ($participant->getParticipationStatus() != $behind) {
|
if ($participant->getParticipationStatus() != $behind) {
|
||||||
$participant->setBehindTransactionPHID($xaction_phid);
|
$participant->setBehindTransactionPHID($xaction_phid);
|
||||||
|
// decrement one as this is the message putting them behind!
|
||||||
|
$participant->setSeenMessageCount($object->getMessageCount() - 1);
|
||||||
}
|
}
|
||||||
$participant->setParticipationStatus($behind);
|
$participant->setParticipationStatus($behind);
|
||||||
$participant->setDateTouched($time);
|
$participant->setDateTouched($time);
|
||||||
} else {
|
} else {
|
||||||
|
$participant->setSeenMessageCount($object->getMessageCount());
|
||||||
$participant->setParticipationStatus($up_to_date);
|
$participant->setParticipationStatus($up_to_date);
|
||||||
$participant->setDateTouched($time);
|
$participant->setDateTouched($time);
|
||||||
}
|
}
|
||||||
|
@ -176,8 +212,10 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
foreach ($add as $phid) {
|
foreach ($add as $phid) {
|
||||||
if ($phid == $this->getActor()->getPHID()) {
|
if ($phid == $this->getActor()->getPHID()) {
|
||||||
$status = ConpherenceParticipationStatus::UP_TO_DATE;
|
$status = ConpherenceParticipationStatus::UP_TO_DATE;
|
||||||
|
$message_count = $object->getMessageCount();
|
||||||
} else {
|
} else {
|
||||||
$status = ConpherenceParticipationStatus::BEHIND;
|
$status = ConpherenceParticipationStatus::BEHIND;
|
||||||
|
$message_count = 0;
|
||||||
}
|
}
|
||||||
$participants[$phid] =
|
$participants[$phid] =
|
||||||
id(new ConpherenceParticipant())
|
id(new ConpherenceParticipant())
|
||||||
|
@ -186,6 +224,7 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
->setParticipationStatus($status)
|
->setParticipationStatus($status)
|
||||||
->setDateTouched(time())
|
->setDateTouched(time())
|
||||||
->setBehindTransactionPHID($xaction->getPHID())
|
->setBehindTransactionPHID($xaction->getPHID())
|
||||||
|
->setSeenMessageCount($message_count)
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
$object->attachParticipants($participants);
|
$object->attachParticipants($participants);
|
||||||
|
|
|
@ -9,6 +9,7 @@ final class ConpherenceParticipant extends ConpherenceDAO {
|
||||||
protected $conpherencePHID;
|
protected $conpherencePHID;
|
||||||
protected $participationStatus;
|
protected $participationStatus;
|
||||||
protected $behindTransactionPHID;
|
protected $behindTransactionPHID;
|
||||||
|
protected $seenMessageCount;
|
||||||
protected $dateTouched;
|
protected $dateTouched;
|
||||||
protected $settings = array();
|
protected $settings = array();
|
||||||
|
|
||||||
|
@ -24,10 +25,13 @@ final class ConpherenceParticipant extends ConpherenceDAO {
|
||||||
return nonempty($this->settings, array());
|
return nonempty($this->settings, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markUpToDate(ConpherenceTransaction $xaction) {
|
public function markUpToDate(
|
||||||
|
ConpherenceThread $conpherence,
|
||||||
|
ConpherenceTransaction $xaction) {
|
||||||
if (!$this->isUpToDate()) {
|
if (!$this->isUpToDate()) {
|
||||||
$this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE);
|
$this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE);
|
||||||
$this->setBehindTransactionPHID($xaction->getPHID());
|
$this->setBehindTransactionPHID($xaction->getPHID());
|
||||||
|
$this->setSeenMessageCount($conpherence->getMessageCount());
|
||||||
$this->save();
|
$this->save();
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -9,6 +9,8 @@ final class ConpherenceThread extends ConpherenceDAO
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $phid;
|
protected $phid;
|
||||||
protected $title;
|
protected $title;
|
||||||
|
protected $messageCount;
|
||||||
|
protected $recentParticipantPHIDs = array();
|
||||||
protected $imagePHIDs = array();
|
protected $imagePHIDs = array();
|
||||||
protected $mailKey;
|
protected $mailKey;
|
||||||
|
|
||||||
|
@ -23,7 +25,8 @@ final class ConpherenceThread extends ConpherenceDAO
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
self::CONFIG_SERIALIZATION => array(
|
self::CONFIG_SERIALIZATION => array(
|
||||||
'imagePHIDs' => self::SERIALIZATION_JSON,
|
'recentParticipantPHIDs' => self::SERIALIZATION_JSON,
|
||||||
|
'imagePHIDs' => self::SERIALIZATION_JSON,
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1226,7 +1226,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('20130330.phrequent.sql'),
|
'name' => $this->getPatchPath('20130330.phrequent.sql'),
|
||||||
),
|
),
|
||||||
|
'20130403.conpherencecache.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('20130403.conpherencecache.sql'),
|
||||||
|
),
|
||||||
|
'20130403.conpherencecachemig.php' => array(
|
||||||
|
'type' => 'php',
|
||||||
|
'name' => $this->getPatchPath('20130403.conpherencecachemig.php'),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue