Page MenuHomePhabricator

D14320.diff
No OneTemporary

D14320.diff

diff --git a/resources/sql/autopatches/20151023.patchduration.sql b/resources/sql/autopatches/20151023.patchduration.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20151023.patchduration.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_meta_data.patch_status
+ ADD duration BIGINT UNSIGNED;
diff --git a/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php b/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php
--- a/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php
+++ b/src/infrastructure/storage/management/PhabricatorStorageManagementAPI.php
@@ -17,6 +17,8 @@
const COLLATE_SORT = 'COLLATE_SORT';
const COLLATE_FULLTEXT = 'COLLATE_FULLTEXT';
+ const TABLE_STATUS = 'patch_status';
+
public function setDisableUTF8MB4($disable_utf8_mb4) {
$this->disableUTF8MB4 = $disable_utf8_mb4;
return $this;
@@ -118,13 +120,26 @@
try {
$applied = queryfx_all(
$this->getConn('meta_data'),
- 'SELECT patch FROM patch_status');
+ 'SELECT patch FROM %T',
+ self::TABLE_STATUS);
return ipull($applied, 'patch');
} catch (AphrontQueryException $ex) {
return null;
}
}
+ public function getPatchDurations() {
+ try {
+ $rows = queryfx_all(
+ $this->getConn('meta_data'),
+ 'SELECT patch, duration FROM %T WHERE duration IS NOT NULL',
+ self::TABLE_STATUS);
+ return ipull($rows, 'duration', 'patch');
+ } catch (AphrontQueryException $ex) {
+ return array();
+ }
+ }
+
public function createDatabase($fragment) {
$info = $this->getCharsetInfo();
@@ -168,13 +183,30 @@
return $legacy;
}
- public function markPatchApplied($patch) {
+ public function markPatchApplied($patch, $duration = null) {
+ $conn = $this->getConn('meta_data');
+
queryfx(
- $this->getConn('meta_data'),
+ $conn,
'INSERT INTO %T (patch, applied) VALUES (%s, %d)',
- 'patch_status',
+ self::TABLE_STATUS,
$patch,
time());
+
+ // We didn't add this column for a long time, so it may not exist yet.
+ if ($duration !== null) {
+ try {
+ queryfx(
+ $conn,
+ 'UPDATE %T SET duration = %d WHERE patch = %s',
+ self::TABLE_STATUS,
+ (int)floor($duration * 1000000),
+ $patch);
+ } catch (AphrontQueryException $ex) {
+ // Just ignore this, as it almost certainly indicates that we just
+ // don't have the column yet.
+ }
+ }
}
public function applyPatch(PhabricatorStoragePatch $patch) {
diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php
--- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php
+++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php
@@ -29,15 +29,26 @@
->setShowHeader(false)
->addColumn('id', array('title' => pht('ID')))
->addColumn('status', array('title' => pht('Status')))
+ ->addColumn('duration', array('title' => pht('Duration')))
->addColumn('type', array('title' => pht('Type')))
->addColumn('name', array('title' => pht('Name')));
+ $durations = $api->getPatchDurations();
+
foreach ($patches as $patch) {
+ $duration = idx($durations, $patch->getFullKey());
+ if ($duration === null) {
+ $duration = '-';
+ } else {
+ $duration = pht('%s us', new PhutilNumber($duration));
+ }
+
$table->addRow(array(
'id' => $patch->getFullKey(),
'status' => in_array($patch->getFullKey(), $applied)
? pht('Applied')
: pht('Not Applied'),
+ 'duration' => $duration,
'type' => $patch->getType(),
'name' => $patch->getName(),
));
diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php
--- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php
+++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php
@@ -187,9 +187,13 @@
echo pht("DRYRUN: Would apply patch '%s'.", $key)."\n";
} else {
echo pht("Applying patch '%s'...", $key)."\n";
+
+ $t_begin = microtime(true);
$api->applyPatch($patch);
+ $t_end = microtime(true);
+
if (!$skip_mark) {
- $api->markPatchApplied($key);
+ $api->markPatchApplied($key, ($t_end - $t_begin));
}
}
diff --git a/src/infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php b/src/infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php
--- a/src/infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php
+++ b/src/infrastructure/storage/schema/PhabricatorStorageSchemaSpec.php
@@ -10,6 +10,7 @@
array(
'patch' => 'text128',
'applied' => 'uint32',
+ 'duration' => 'uint64?',
),
array(
'PRIMARY' => array(

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 3:22 AM (5 m, 9 s)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6912652
Default Alt Text
D14320.diff (5 KB)

Event Timeline