1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Move task/project storage to edges

Summary: Ref T5245. This moves the actual storage over and stops reads and writes to the old table.

Test Plan:
  - Verified tasks retained projects across the migration.
  - Added and removed projects from tasks.
  - Searched for: all, any, users' projects, not-in-projects, no-projects.

Reviewers: chad, btrahan, joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T5245

Differential Revision: https://secure.phabricator.com/D9850
This commit is contained in:
epriestley 2014-07-17 15:42:30 -07:00
parent 33120e377a
commit aa79539789
4 changed files with 63 additions and 43 deletions

View file

@ -0,0 +1,10 @@
/* PhabricatorProjectObjectHasProjectEdgeType::EDGECONST = 41 */
/* PhabricatorProjectProjectHasObjectEdgeType::EDGECONST = 42 */
INSERT IGNORE INTO {$NAMESPACE}_maniphest.edge (src, type, dst)
SELECT taskPHID, 41, projectPHID
FROM {$NAMESPACE}_maniphest.maniphest_taskproject;
INSERT IGNORE INTO {$NAMESPACE}_project.edge (src, type, dst)
SELECT projectPHID, 42, taskPHID
FROM {$NAMESPACE}_maniphest.maniphest_taskproject;

View file

@ -83,9 +83,10 @@ final class ManiphestReportController extends ManiphestController {
$joins = qsprintf(
$conn,
'JOIN %T t ON x.objectPHID = t.phid
JOIN %T p ON p.taskPHID = t.phid AND p.projectPHID = %s',
JOIN %T p ON p.src = t.phid AND p.type = %d AND p.dst = %s',
id(new ManiphestTask())->getTableName(),
id(new ManiphestTaskProject())->getTableName(),
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
$project_phid);
}

View file

@ -243,7 +243,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
// query. We sum the project count and require it be the same as the
// number of projects we're searching for.
$count = ', COUNT(project.projectPHID) projectCount';
$count = ', COUNT(project.dst) projectCount';
$having = qsprintf(
$conn,
'HAVING projectCount = %d',
@ -496,13 +496,13 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
if ($this->projectPHIDs) {
$parts[] = qsprintf(
$conn,
'project.projectPHID in (%Ls)',
'project.dst in (%Ls)',
$this->projectPHIDs);
}
if ($this->includeNoProject) {
$parts[] = qsprintf(
$conn,
'project.projectPHID IS NULL');
'project.dst IS NULL');
}
return '('.implode(') OR (', $parts).')';
@ -515,7 +515,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return qsprintf(
$conn,
'anyproject.projectPHID IN (%Ls)',
'anyproject.dst IN (%Ls)',
$this->anyProjectPHIDs);
}
@ -536,7 +536,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return qsprintf(
$conn,
'anyproject.projectPHID IN (%Ls)',
'anyproject.dst IN (%Ls)',
$any_user_project_phids);
}
@ -547,7 +547,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return qsprintf(
$conn,
'xproject.projectPHID IS NULL');
'xproject.dst IS NULL');
}
private function buildCustomOrderClause(AphrontDatabaseConnection $conn) {
@ -636,31 +636,37 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
}
private function buildJoinsClause(AphrontDatabaseConnection $conn_r) {
$project_dao = new ManiphestTaskProject();
$edge_table = PhabricatorEdgeConfig::TABLE_NAME_EDGE;
$joins = array();
if ($this->projectPHIDs || $this->includeNoProject) {
$joins[] = qsprintf(
$conn_r,
'%Q JOIN %T project ON project.taskPHID = task.phid',
'%Q JOIN %T project ON project.src = task.phid
AND project.type = %d',
($this->includeNoProject ? 'LEFT' : ''),
$project_dao->getTableName());
$edge_table,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
}
if ($this->anyProjectPHIDs || $this->anyUserProjectPHIDs) {
$joins[] = qsprintf(
$conn_r,
'JOIN %T anyproject ON anyproject.taskPHID = task.phid',
$project_dao->getTableName());
'JOIN %T anyproject ON anyproject.src = task.phid
AND anyproject.type = %d',
$edge_table,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
}
if ($this->xprojectPHIDs) {
$joins[] = qsprintf(
$conn_r,
'LEFT JOIN %T xproject ON xproject.taskPHID = task.phid
AND xproject.projectPHID IN (%Ls)',
$project_dao->getTableName(),
'LEFT JOIN %T xproject ON xproject.src = task.phid
AND xproject.type = %d
AND xproject.dst IN (%Ls)',
$edge_table,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
$this->xprojectPHIDs);
}
@ -678,20 +684,24 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
if ($ignore_group_phids) {
$joins[] = qsprintf(
$conn_r,
'LEFT JOIN %T projectGroup ON task.phid = projectGroup.taskPHID
AND projectGroup.projectPHID NOT IN (%Ls)',
$project_dao->getTableName(),
'LEFT JOIN %T projectGroup ON task.phid = projectGroup.src
AND projectGroup.type = %d
AND projectGroup.dst NOT IN (%Ls)',
$edge_table,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
$ignore_group_phids);
} else {
$joins[] = qsprintf(
$conn_r,
'LEFT JOIN %T projectGroup ON task.phid = projectGroup.taskPHID',
$project_dao->getTableName());
'LEFT JOIN %T projectGroup ON task.phid = projectGroup.src
AND projectGroup.type = %d',
$edge_table,
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
}
$joins[] = qsprintf(
$conn_r,
'LEFT JOIN %T projectGroupName
ON projectGroup.projectPHID = projectGroupName.indexedObjectPHID',
ON projectGroup.dst = projectGroupName.indexedObjectPHID',
id(new ManiphestNameIndex())->getTableName());
break;
}
@ -712,7 +722,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
// task IDs.
if ($joined_multiple_rows) {
if ($joined_project_name) {
return 'GROUP BY task.phid, projectGroup.projectPHID';
return 'GROUP BY task.phid, projectGroup.dst';
} else {
return 'GROUP BY task.phid';
}

View file

@ -20,30 +20,29 @@ final class ManiphestTaskProject extends ManiphestDAO {
}
public static function updateTaskProjects(ManiphestTask $task) {
$dao = new ManiphestTaskProject();
$conn = $dao->establishConnection('w');
$edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$sql = array();
foreach ($task->getProjectPHIDs() as $project_phid) {
$sql[] = qsprintf(
$conn,
'(%s, %s)',
$task->getPHID(),
$project_phid);
$old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$task->getPHID(),
$edge_type);
$new_phids = $task->getProjectPHIDs();
$add_phids = array_diff($new_phids, $old_phids);
$rem_phids = array_diff($old_phids, $new_phids);
if (!$add_phids && !$rem_phids) {
return;
}
queryfx(
$conn,
'DELETE FROM %T WHERE taskPHID = %s',
$dao->getTableName(),
$task->getPHID());
if ($sql) {
queryfx(
$conn,
'INSERT INTO %T (taskPHID, projectPHID) VALUES %Q',
$dao->getTableName(),
implode(', ', $sql));
$editor = new PhabricatorEdgeEditor();
foreach ($add_phids as $phid) {
$editor->addEdge($task->getPHID(), $edge_type, $phid);
}
foreach ($rem_phids as $phid) {
$editor->remEdge($task->getPHID(), $edge_type, $phid);
}
$editor->save();
}
}