Issue Details (XML | Word | Printable)

Key: MDL-15143
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Nobody
Reporter: Simon MELIX
Votes: 2
Watchers: 6
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Why "role_assign()" && "role_unassign()" takes so much time to execute...?!

Created: 04/Jun/08 05:24 PM   Updated: 18/Jan/09 09:54 PM
Component/s: Enrolments, Performance, Roles
Affects Version/s: 1.9, 1.9.1
Fix Version/s: None

Environment:
Apache2 : Version : 2.2.8-3
PHP : Version : 5.2.5-3
MySQL : Version : 5.0.51a
System : Linux debian-test2 2.6.22-3-686 #1 SMP Mon Nov 12 08:32:57 UTC 2007 i686 GNU/Linux

Server config :
4 cores (3.06 GHz)
4 GB RAM
200GB HDD
Issue Links:
Relates
 

Database: MySQL
Participants: Dan Poltawski, Nobody and Simon MELIX
Security Level: None
Affected Branches: MOODLE_19_STABLE


 Description  « Hide
I explain my problem :
The function role_assign is really heavy.
I made a development to enrol students automatically in their course spaces and groups (it's a synchronization with LDAP).
When I call the function role_assign (or role_unassign it's the same problem), to enrol 186 students in a group and in a context of a course, it takes 213 secs!

So, I tried to understand why before I post in this forum and I think I have a possible reason:
I duplicated the function role_assign in a personalized function called role_assign_iut and I just commented the lines :

/// Do some data validation

if (empty($roleid)) { debugging('Role ID not provided'); return false; }

if (empty($userid) && empty($groupid)) { debugging('Either userid or groupid must be provided'); return false; }

if ($userid && !record_exists('user', 'id', $userid)) { debugging('User ID '.intval($userid).' does not exist!'); return false; }

if ($groupid && !groups_group_exists($groupid)) { debugging('Group ID '.intval($groupid).' does not exist!'); return false; }

if (!$context = get_context_instance_by_id($contextid)) { debugging('Context ID '.intval($contextid).' does not exist!'); return false; }

if (($timestart and $timeend) and ($timestart > $timeend)) { debugging('The end time can not be earlier than the start time'); return false; }

So now, the execution time takes only 2secs!
I just commented these lines because I know my parameters are good, I checked them before the execution.

My questions are :
Why these params verifications takes so long?
Why are these verifications here?
Is it just to be sure the developers like me don't use bad params?

Regards,
MELIX Simon



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Dan Poltawski added a comment - 05/Jun/08 04:28 AM
have you tried just commenting out individual validation functions?

(I would imagine the userrid/ groupid/ context checks would be the slow ones since they are likely to cause a db query per call)