"What is the public API and how do we use it efficiently/scalably?"
Right now, this page is extremely light in API details (hopefully we can beef it up!)
http://docs.moodle.org/en/Development:Roles#Programming_Interface
it only talks about get_context_instance(), as_capability() and require_capability().
But that's only a subset of what we need... naturally there's more. We don't have good details of internal vs external calls in lib/accesslib.php -- . I ended up writing a findcallers.pl utility to figure this out. Accesslib is huge - it has 81 functions.
Looking at the output of findcallers.pl, I found these functions that I think form the rest of the API:
load_all_capabilities()
get_roles_with_capability()
role_assign() role_unassign()
enrol_into_course()
get_all_roles()
get_assignable_roles()
get_default_course_role()
get_users_by_capability()
get_role_users()
get_roles_on_exact_context()
get_user_capability_course()
role_switch()
user_has_role_assignment()
role_get_name()
So I guess my questions are...
- Is this list right?
- Which of those are the key calls, and could we have some "design" notes about them explaining how they are expected to be used?
- Which of those are costly (RAM, CPU, DB load, DB traffic), and how do we minimise their cost?
Pre 1.7, we had the user_students and user_teachers tables, and it was all simple and always cheap to check these things. With the flexibility and abstraction that roles brings, some of these operations are _really_ expensive.
In that sense, I want to work towards making roles much more efficient -- using less db queries, running the queries _outside_ of the loop and caching more smartly. For example, in the scenarios below:
- User looking at courses... this is probably the worst - we spend a huge effort asking if the user can see the course listing, and the teachers' names, and it's horribly costly to list the teachers' names.
- Participants page. Very costly.
- User in course page, or course resources/
activities. I think this is reasonably cached already but the cache seems to be large in memory.
Phew. Long post. More to come.
Edit: attached output of findcallers.pl - the script itself is in
cvs:/contrib/tools/devtools/findcallers.pl