I am not sure what exactly happens when this function is called but when ever I am waiting for the a page to finish showing me a list of courses for a person I see the following proccess running in mySQL.
Copying to tmp table
SELECT rc.capability, c1.id AS id1, c2.id AS id2, (
c1.contextlevel *100 + c2.contextlevel
) AS aggrl
I know from past experience that when mySQL uses a tmp table performance suffers tremendously I am guessing that some SQL is being generated poorly by the function call.
Also I am noticing that course creators of the site for some reason are marked as participants in all the courses when their profile is viewed but administrators are not. Is their some reason for that?