1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00
phorge-phorge/resources/sql/patches/20130403.conpherencecachemig.php
Bob Trahan 754705df4e 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
2013-04-04 16:57:38 -07:00

64 lines
1.8 KiB
PHP

<?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";