Skip to content

Commit 3b392f7

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 45a2d16 commit 3b392f7

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
@@ -1019,12 +1019,18 @@ function user_get_all_accessible_subprojects( $p_user_id, $p_project_id ) {
10191019

10201020
function user_get_all_accessible_projects( $p_user_id, $p_project_id ) {
10211021
if( ALL_PROJECTS == $p_project_id ) {
1022-
$t_topprojects = $t_project_ids = user_get_accessible_projects( $p_user_id );
1022+
$t_topprojects = user_get_accessible_projects( $p_user_id );
1023+
1024+
# Create a combined array where key = value
1025+
$t_project_ids = array_combine( $t_topprojects, $t_topprojects );
1026+
1027+
# Add all subprojects user has access to
10231028
foreach( $t_topprojects as $t_project ) {
1024-
$t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $p_user_id, $t_project ) );
1029+
$t_subprojects_ids = user_get_all_accessible_subprojects( $p_user_id, $t_project );
1030+
foreach( $t_subprojects_ids as $t_id ) {
1031+
$t_project_ids[$t_id] = $t_id;
1032+
}
10251033
}
1026-
1027-
$t_project_ids = array_unique( $t_project_ids );
10281034
} else {
10291035
access_ensure_project_level( VIEWER, $p_project_id );
10301036
$t_project_ids = user_get_all_accessible_subprojects( $p_user_id, $p_project_id );

0 commit comments

Comments
 (0)
Please sign in to comment.