Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc7703a

Browse files
committedMay 1, 2013
Optimize user_get_all_accessible_projects()
On instances having a large number of projects, this function would consume significant resources while processing all the subprojects to determine if one is accessible to the user (about 25 seconds to load main_page.php for 5'000 projects, without subprojects). The performance bottleneck was the array_merge() call in the loop. This has been replaced by a foreach working on an associative array. The same page now loads under 1 second. Fixes #9876
1 parent c4f6493 commit cc7703a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎core/user_api.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,18 @@ function user_get_all_accessible_subprojects( $p_user_id, $p_project_id ) {
10081008

10091009
function user_get_all_accessible_projects( $p_user_id, $p_project_id ) {
10101010
if( ALL_PROJECTS == $p_project_id ) {
1011-
$t_topprojects = $t_project_ids = user_get_accessible_projects( $p_user_id );
1011+
$t_topprojects = user_get_accessible_projects( $p_user_id );
1012+
1013+
# Create a combined array where key = value
1014+
$t_project_ids = array_combine( $t_topprojects, $t_topprojects );
1015+
1016+
# Add all subprojects user has access to
10121017
foreach( $t_topprojects as $t_project ) {
1013-
$t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $p_user_id, $t_project ) );
1018+
$t_subprojects_ids = user_get_all_accessible_subprojects( $p_user_id, $t_project );
1019+
foreach( $t_subprojects_ids as $t_id ) {
1020+
$t_project_ids[$t_id] = $t_id;
1021+
}
10141022
}
1015-
1016-
$t_project_ids = array_unique( $t_project_ids );
10171023
} else {
10181024
access_ensure_project_level( VIEWER, $p_project_id );
10191025
$t_project_ids = user_get_all_accessible_subprojects( $p_user_id, $p_project_id );

0 commit comments

Comments
 (0)
Please sign in to comment.