From 01ea84029d88b0fb5f276aab50fd9b253b4b2117 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 15 Mar 2021 15:32:12 -0700 Subject: [PATCH] Update table schema for "AffectedPath" table Summary: Ref T13639. Make schema changes: - Make repositoryID nullable, for revisions with no repository. - Remove "epoch", which has no readers and no clear use. - Change the ordering of the key, since "pathID" has more unique values and no queries ever issue without it. Test Plan: - Ran `bin/storage upgrade`, got a clean schema. - Reindexed all revisions with an external script. - Reviewed index via debug UI, saw appropriate index for non-repositoy revisions. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13639 Differential Revision: https://secure.phabricator.com/D21617 --- .../sql/autopatches/20210315.affectedpath.01.epoch.sql | 2 ++ .../autopatches/20210315.affectedpath.02.repositoryid.sql | 2 ++ .../engine/DifferentialAffectedPathEngine.php | 7 +++---- .../differential/storage/DifferentialAffectedPath.php | 8 ++++---- 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 resources/sql/autopatches/20210315.affectedpath.01.epoch.sql create mode 100644 resources/sql/autopatches/20210315.affectedpath.02.repositoryid.sql diff --git a/resources/sql/autopatches/20210315.affectedpath.01.epoch.sql b/resources/sql/autopatches/20210315.affectedpath.01.epoch.sql new file mode 100644 index 0000000000..80c337fd94 --- /dev/null +++ b/resources/sql/autopatches/20210315.affectedpath.01.epoch.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_differential.differential_affectedpath + DROP epoch; diff --git a/resources/sql/autopatches/20210315.affectedpath.02.repositoryid.sql b/resources/sql/autopatches/20210315.affectedpath.02.repositoryid.sql new file mode 100644 index 0000000000..1975b7c071 --- /dev/null +++ b/resources/sql/autopatches/20210315.affectedpath.02.repositoryid.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_differential.differential_affectedpath + CHANGE repositoryID repositoryID INT UNSIGNED; diff --git a/src/applications/differential/engine/DifferentialAffectedPathEngine.php b/src/applications/differential/engine/DifferentialAffectedPathEngine.php index cdf1c168b1..0ac85e5900 100644 --- a/src/applications/differential/engine/DifferentialAffectedPathEngine.php +++ b/src/applications/differential/engine/DifferentialAffectedPathEngine.php @@ -32,7 +32,7 @@ final class DifferentialAffectedPathEngine if ($repository) { $repository_id = $repository->getID(); } else { - return; + $repository_id = null; } $paths = $this->getAffectedPaths(); @@ -48,10 +48,9 @@ final class DifferentialAffectedPathEngine foreach ($path_ids as $path_id) { $sql[] = qsprintf( $conn, - '(%d, %d, %d, %d)', + '(%nd, %d, %d)', $repository_id, $path_id, - PhabricatorTime::getNow(), $revision->getID()); } @@ -64,7 +63,7 @@ final class DifferentialAffectedPathEngine foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { queryfx( $conn, - 'INSERT INTO %R (repositoryID, pathID, epoch, revisionID) VALUES %LQ', + 'INSERT INTO %R (repositoryID, pathID, revisionID) VALUES %LQ', $table, $chunk); } diff --git a/src/applications/differential/storage/DifferentialAffectedPath.php b/src/applications/differential/storage/DifferentialAffectedPath.php index b8de95629b..400a09fe82 100644 --- a/src/applications/differential/storage/DifferentialAffectedPath.php +++ b/src/applications/differential/storage/DifferentialAffectedPath.php @@ -8,7 +8,6 @@ final class DifferentialAffectedPath extends DifferentialDAO { protected $repositoryID; protected $pathID; - protected $epoch; protected $revisionID; protected function getConfiguration() { @@ -16,15 +15,16 @@ final class DifferentialAffectedPath extends DifferentialDAO { self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'id' => null, + 'repositoryID' => 'id?', ), self::CONFIG_KEY_SCHEMA => array( 'PRIMARY' => null, - 'repositoryID' => array( - 'columns' => array('repositoryID', 'pathID', 'epoch'), - ), 'revisionID' => array( 'columns' => array('revisionID'), ), + 'key_path' => array( + 'columns' => array('pathID', 'repositoryID'), + ), ), ) + parent::getConfiguration(); }