1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 04:42:40 +01:00

Read materialized project members instead of real members

Summary:
Ref T10010. This will allow us to find superprojects with `withMemberPHIDs(...)` queries.

  - Copy all the current real member edges to materialized member edges.
  - Redirect all reads to look at materialized members.
  - This table is already kept in sync by earlier work with indexing.

Basically, flow is:

  - Writes (joining, leaving, adding/removing members) write to the real member edge type.
  - After a project's members change, they're copied to the materialized member edge type for that project and all of its superprojects.
  - Reads look at materialized members, so "Parent" sees the members of "Child" and "Grandchild" as its own members, but we still have the "real members" edge type to keep track of "natural" or "direct" members.

Test Plan:
  - Ran migration.
  - Ran unit tests.
  - Saw the same projects as projects I was a member of.
  - Added some `var_dump()` stuff to verify the Owners changed.
  - Used `grep` to look for other readers of this edge type.
  - Made some project updates.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10010

Differential Revision: https://secure.phabricator.com/D14893
This commit is contained in:
epriestley 2015-12-27 04:27:58 -08:00
parent 77897ce862
commit 373ff7f9d4
4 changed files with 36 additions and 26 deletions

View file

@ -0,0 +1,6 @@
/* PhabricatorProjectProjectHasMemberEdgeType::EDGECONST = 13 */
/* PhabricatorProjectMaterializedMemberEdgeType::EDGECONST = 60 */
INSERT IGNORE INTO {$NAMESPACE}_project.edge (src, type, dst, dateCreated)
SELECT src, 60, dst, dateCreated FROM {$NAMESPACE}_project.edge
WHERE type = 13;

View file

@ -40,6 +40,7 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
if (!$package_ids) { if (!$package_ids) {
return array(); return array();
} }
$owners = id(new PhabricatorOwnersOwner())->loadAllWhere( $owners = id(new PhabricatorOwnersOwner())->loadAllWhere(
'packageID IN (%Ls)', 'packageID IN (%Ls)',
$package_ids); $package_ids);
@ -50,20 +51,19 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
PhabricatorPeopleUserPHIDType::TYPECONST, PhabricatorPeopleUserPHIDType::TYPECONST,
array()); array());
$users_in_project_phids = array(); if ($user_phids) {
$project_phids = idx( $projects = id(new PhabricatorProjectQuery())
$all_phids, ->setViewer(PhabricatorUser::getOmnipotentUser())
PhabricatorProjectProjectPHIDType::TYPECONST); ->withMemberPHIDs($user_phids)
if ($project_phids) { ->withIsMilestone(false)
$query = id(new PhabricatorEdgeQuery()) ->execute();
->withSourcePHIDs($project_phids) $project_phids = mpull($projects, 'getPHID');
->withEdgeTypes(array( } else {
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST, $project_phids = array();
));
$query->execute();
$users_in_project_phids = $query->getDestinationPHIDs();
} }
return array_unique(array_merge($users_in_project_phids, $user_phids)); $all_phids = array_fuse($user_phids) + array_fuse($project_phids);
return array_values($all_phids);
} }
} }

View file

@ -509,12 +509,13 @@ final class PhabricatorProjectTransactionEditor
} }
protected function willPublish(PhabricatorLiskDAO $object, array $xactions) { protected function willPublish(PhabricatorLiskDAO $object, array $xactions) {
$member_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( // NOTE: We're using the omnipotent user here because the original actor
$object->getPHID(), // may no longer have permission to view the object.
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST); return id(new PhabricatorProjectQuery())
$object->attachMemberPHIDs($member_phids); ->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($object->getPHID()))
return $object; ->needMembers(true)
->executeOne();
} }
protected function shouldSendMail( protected function shouldSendMail(
@ -719,9 +720,12 @@ final class PhabricatorProjectTransactionEditor
$object_phid = $object->getPHID(); $object_phid = $object->getPHID();
if ($object_phid) { if ($object_phid) {
$members = PhabricatorEdgeQuery::loadDestinationPHIDs( $project = id(new PhabricatorProjectQuery())
$object_phid, ->setViewer($this->getActor())
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST); ->withPHIDs(array($object_phid))
->needMembers(true)
->executeOne();
$members = $project->getMemberPHIDs();
} else { } else {
$members = array(); $members = array();
} }

View file

@ -201,11 +201,11 @@ final class PhabricatorProjectQuery
$viewer_phid = $this->getViewer()->getPHID(); $viewer_phid = $this->getViewer()->getPHID();
$member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST;
$watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST; $watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
$types = array(); $types = array();
$types[] = $member_type; $types[] = $material_type;
if ($this->needWatchers) { if ($this->needWatchers) {
$types[] = $watcher_type; $types[] = $watcher_type;
} }
@ -255,7 +255,7 @@ final class PhabricatorProjectQuery
if ($any_edges) { if ($any_edges) {
$member_phids = $edge_query->getDestinationPHIDs( $member_phids = $edge_query->getDestinationPHIDs(
$source_phids, $source_phids,
array($member_type)); array($material_type));
} else { } else {
$member_phids = array(); $member_phids = array();
} }
@ -488,7 +488,7 @@ final class PhabricatorProjectQuery
$conn, $conn,
'JOIN %T e ON e.src = p.phid AND e.type = %d', 'JOIN %T e ON e.src = p.phid AND e.type = %d',
PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorEdgeConfig::TABLE_NAME_EDGE,
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST); PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
} }
if ($this->slugs !== null) { if ($this->slugs !== null) {