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:
parent
77897ce862
commit
373ff7f9d4
4 changed files with 36 additions and 26 deletions
|
@ -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;
|
|
@ -40,6 +40,7 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
|
|||
if (!$package_ids) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$owners = id(new PhabricatorOwnersOwner())->loadAllWhere(
|
||||
'packageID IN (%Ls)',
|
||||
$package_ids);
|
||||
|
@ -50,20 +51,19 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
|
|||
PhabricatorPeopleUserPHIDType::TYPECONST,
|
||||
array());
|
||||
|
||||
$users_in_project_phids = array();
|
||||
$project_phids = idx(
|
||||
$all_phids,
|
||||
PhabricatorProjectProjectPHIDType::TYPECONST);
|
||||
if ($project_phids) {
|
||||
$query = id(new PhabricatorEdgeQuery())
|
||||
->withSourcePHIDs($project_phids)
|
||||
->withEdgeTypes(array(
|
||||
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST,
|
||||
));
|
||||
$query->execute();
|
||||
$users_in_project_phids = $query->getDestinationPHIDs();
|
||||
if ($user_phids) {
|
||||
$projects = id(new PhabricatorProjectQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withMemberPHIDs($user_phids)
|
||||
->withIsMilestone(false)
|
||||
->execute();
|
||||
$project_phids = mpull($projects, 'getPHID');
|
||||
} else {
|
||||
$project_phids = array();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -509,12 +509,13 @@ final class PhabricatorProjectTransactionEditor
|
|||
}
|
||||
|
||||
protected function willPublish(PhabricatorLiskDAO $object, array $xactions) {
|
||||
$member_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$object->getPHID(),
|
||||
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
|
||||
$object->attachMemberPHIDs($member_phids);
|
||||
|
||||
return $object;
|
||||
// NOTE: We're using the omnipotent user here because the original actor
|
||||
// may no longer have permission to view the object.
|
||||
return id(new PhabricatorProjectQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->needMembers(true)
|
||||
->executeOne();
|
||||
}
|
||||
|
||||
protected function shouldSendMail(
|
||||
|
@ -719,9 +720,12 @@ final class PhabricatorProjectTransactionEditor
|
|||
$object_phid = $object->getPHID();
|
||||
|
||||
if ($object_phid) {
|
||||
$members = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
||||
$object_phid,
|
||||
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
|
||||
$project = id(new PhabricatorProjectQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withPHIDs(array($object_phid))
|
||||
->needMembers(true)
|
||||
->executeOne();
|
||||
$members = $project->getMemberPHIDs();
|
||||
} else {
|
||||
$members = array();
|
||||
}
|
||||
|
|
|
@ -201,11 +201,11 @@ final class PhabricatorProjectQuery
|
|||
|
||||
$viewer_phid = $this->getViewer()->getPHID();
|
||||
|
||||
$member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
|
||||
$material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST;
|
||||
$watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
||||
|
||||
$types = array();
|
||||
$types[] = $member_type;
|
||||
$types[] = $material_type;
|
||||
if ($this->needWatchers) {
|
||||
$types[] = $watcher_type;
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ final class PhabricatorProjectQuery
|
|||
if ($any_edges) {
|
||||
$member_phids = $edge_query->getDestinationPHIDs(
|
||||
$source_phids,
|
||||
array($member_type));
|
||||
array($material_type));
|
||||
} else {
|
||||
$member_phids = array();
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ final class PhabricatorProjectQuery
|
|||
$conn,
|
||||
'JOIN %T e ON e.src = p.phid AND e.type = %d',
|
||||
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
||||
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
|
||||
PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
|
||||
}
|
||||
|
||||
if ($this->slugs !== null) {
|
||||
|
|
Loading…
Reference in a new issue