mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Allow unit tests to have arbitrarily long names (>255 characters)
Summary: Depends on D20179. Ref T13088. See PHI351. See PHI1018. In various cases, unit tests names are 19 paths mashed together. This is probably not an ideal name, and the test harness should probably pick a better name, but if users are fine with it and don't want to do the work to summarize on their own, accept them. We may summarize with "..." in some cases depending on how this fares in the UI. The actual implementation is a separate "strings" table which is just `<hash-of-string, full-string>`. The unit message table can end up being mostly strings, so this should reduce storage requirements a bit. For now, I'm not forcing a migration: new writes use the new table, existing rows retain the data. I plan to provide a migration tool, recommend migration, then force migration eventually. Prior to that, I'm likely to move at least some other columns to use this table (e.g., lint names), since we have a lot of similar data (arbitrarily long user string constants that we are unlikely to need to search or filter). Test Plan: {F6213819} Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13088 Differential Revision: https://secure.phabricator.com/D20180
This commit is contained in:
parent
312ba30714
commit
deea2f01f5
6 changed files with 124 additions and 0 deletions
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_string (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
stringIndex BINARY(12) NOT NULL,
|
||||
stringValue LONGTEXT NOT NULL,
|
||||
UNIQUE KEY `key_string` (stringIndex)
|
||||
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_harbormaster.harbormaster_buildunitmessage
|
||||
ADD nameIndex BINARY(12) NOT NULL;
|
|
@ -1441,6 +1441,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterStepDeleteController' => 'applications/harbormaster/controller/HarbormasterStepDeleteController.php',
|
||||
'HarbormasterStepEditController' => 'applications/harbormaster/controller/HarbormasterStepEditController.php',
|
||||
'HarbormasterStepViewController' => 'applications/harbormaster/controller/HarbormasterStepViewController.php',
|
||||
'HarbormasterString' => 'applications/harbormaster/storage/HarbormasterString.php',
|
||||
'HarbormasterTargetEngine' => 'applications/harbormaster/engine/HarbormasterTargetEngine.php',
|
||||
'HarbormasterTargetSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterTargetSearchAPIMethod.php',
|
||||
'HarbormasterTargetWorker' => 'applications/harbormaster/worker/HarbormasterTargetWorker.php',
|
||||
|
@ -7070,6 +7071,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterStepDeleteController' => 'HarbormasterPlanController',
|
||||
'HarbormasterStepEditController' => 'HarbormasterPlanController',
|
||||
'HarbormasterStepViewController' => 'HarbormasterPlanController',
|
||||
'HarbormasterString' => 'HarbormasterDAO',
|
||||
'HarbormasterTargetEngine' => 'Phobject',
|
||||
'HarbormasterTargetSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'HarbormasterTargetWorker' => 'HarbormasterWorker',
|
||||
|
|
|
@ -57,6 +57,37 @@ final class HarbormasterBuildUnitMessageQuery
|
|||
return $where;
|
||||
}
|
||||
|
||||
protected function didFilterPage(array $messages) {
|
||||
$indexes = array();
|
||||
foreach ($messages as $message) {
|
||||
$index = $message->getNameIndex();
|
||||
if (strlen($index)) {
|
||||
$indexes[$index] = $index;
|
||||
}
|
||||
}
|
||||
|
||||
if ($indexes) {
|
||||
$map = HarbormasterString::newIndexMap($indexes);
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$index = $message->getNameIndex();
|
||||
|
||||
if (!strlen($index)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = idx($map, $index);
|
||||
if ($name === null) {
|
||||
$name = pht('Unknown Unit Message ("%s")', $index);
|
||||
}
|
||||
|
||||
$message->setName($name);
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
return 'PhabricatorHarbormasterApplication';
|
||||
}
|
||||
|
|
54
src/applications/harbormaster/storage/HarbormasterString.php
Normal file
54
src/applications/harbormaster/storage/HarbormasterString.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterString
|
||||
extends HarbormasterDAO {
|
||||
|
||||
protected $stringIndex;
|
||||
protected $stringValue;
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_TIMESTAMPS => false,
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'stringIndex' => 'bytes12',
|
||||
'stringValue' => 'text',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_string' => array(
|
||||
'columns' => array('stringIndex'),
|
||||
'unique' => true,
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public static function newIndex($string) {
|
||||
$index = PhabricatorHash::digestForIndex($string);
|
||||
|
||||
$table = new self();
|
||||
$conn = $table->establishConnection('w');
|
||||
|
||||
queryfx(
|
||||
$conn,
|
||||
'INSERT IGNORE INTO %R (stringIndex, stringValue) VALUES (%s, %s)',
|
||||
$table,
|
||||
$index,
|
||||
$string);
|
||||
|
||||
return $index;
|
||||
}
|
||||
|
||||
public static function newIndexMap(array $indexes) {
|
||||
$table = new self();
|
||||
$conn = $table->establishConnection('r');
|
||||
|
||||
$rows = queryfx_all(
|
||||
$conn,
|
||||
'SELECT stringIndex, stringValue FROM %R WHERE stringIndex IN (%Ls)',
|
||||
$table,
|
||||
$indexes);
|
||||
|
||||
return ipull($rows, 'stringValue', 'stringIndex');
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ final class HarbormasterBuildUnitMessage
|
|||
protected $engine;
|
||||
protected $namespace;
|
||||
protected $name;
|
||||
protected $nameIndex;
|
||||
protected $result;
|
||||
protected $duration;
|
||||
protected $properties = array();
|
||||
|
@ -132,6 +133,7 @@ final class HarbormasterBuildUnitMessage
|
|||
'engine' => 'text255',
|
||||
'namespace' => 'text255',
|
||||
'name' => 'text255',
|
||||
'nameIndex' => 'bytes12',
|
||||
'result' => 'text32',
|
||||
'duration' => 'double?',
|
||||
),
|
||||
|
@ -260,6 +262,33 @@ final class HarbormasterBuildUnitMessage
|
|||
return implode("\0", $parts);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if ($this->nameIndex === null) {
|
||||
$this->nameIndex = HarbormasterString::newIndex($this->getName());
|
||||
}
|
||||
|
||||
// See T13088. While we're letting installs do online migrations to avoid
|
||||
// downtime, don't populate the "name" column for new writes. New writes
|
||||
// use the "HarbormasterString" table instead.
|
||||
$old_name = $this->name;
|
||||
$this->name = '';
|
||||
|
||||
$caught = null;
|
||||
try {
|
||||
$result = parent::save();
|
||||
} catch (Exception $ex) {
|
||||
$caught = $ex;
|
||||
}
|
||||
|
||||
$this->name = $old_name;
|
||||
|
||||
if ($caught) {
|
||||
throw $caught;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
Loading…
Reference in a new issue