Commit graph

903 commits

Author SHA1 Message Date
martinlanghoff
573674bf47 accesslib: get_user_courses_bycap() is less of a piggy now...
get_user_courses_bycap() replaces get_courses_bycap_fromsess().

Using a combination of in-DB enrolments and in-session capability
checks, we narrow down the courses we fetch from the DB for checking.

This patch adds a small DB query, and has has a moderate impact on
the timings observable on my laptop (~300ms?), but reduces
*significantly* the bandwidth used, which in cluster environments
with frontends separate from backends has a serious impact.
2007-09-19 07:04:23 +00:00
martinlanghoff
aeb3916b7a datalib: get_my_courses() - some fixes to the data we return
strangely, get_my_courses() is expected to return the
array keyed on id, which messes up the sorting

So let's do it ;-)
2007-09-19 07:04:10 +00:00
martinlanghoff
e1d5e5c181 accesslib: get_my_courses() rework, new get_courses_bycap_fromsess()
get_my_courses() goes from a bazillion queries (500 in some sample
cases) to 1 for the logged-in user, and 4 for a non-logged-in user.

One of those queries brings a *lot* of data across (all rows from
mdl_course) so there is room for serious optimisation.

  However, this clocks at ~300 ms on my laptop, costly, but not
  the end of the world. If your PHP-DB link has bandwidth probs
  it might be a problem.

A few important changes to get_my_courses()

 - (Compat ALERT!) the default fields are less than before --
   (will be followed by patches that fix the callers!) our defaults
   had grown to quite a bit because of the crazy caching scheme it had

 - the $fields parameter is to name _additional_ fields you need, and
   ideally wants them passed as an array. Will cope with old-style
   strings too.

 - the returned courses have an extra property "context" that is
   a fully valid context object, so if the caller needs to perform
   further accesslib checks, we save a query per course down the road

The work is done in the newfangled get_courses_bycap_fromsess()
which is brute-force but fast. I'm sure we can optimise the common
cases a lot in it if we try. It'd be worthwhile to

  - reduce the rows we grab - that's really boneheaded

  - if we copy and tweak the logic of has_cap_fromsess() in it
    it can be made even faster
2007-09-19 07:03:49 +00:00
martinlanghoff
13a794757e accesslib: has_capability() - useful debugging bit... 2007-09-19 07:03:34 +00:00
martinlanghoff
018d4b52b7 accesslib: get_user_access_bycontext() fetches overrides in subcontexts, intro aggr_roles_fromsess()
The main thing here is that overrides in subcontexts are
now read correctly (and still cheaply) into the access array.

Also

 - introducing aggr_roles_fromsess() with gives you a list of
   the relevant roles that affect the user in this context

 - we clear out $USER->access on login/logout

 - get_user_access_bycontext() gets a few optimisations too...
2007-09-19 07:03:19 +00:00
martinlanghoff
e0376a6241 accesslib: default, guest and notloggedin roles work properly now
Changes around load_user_capability() and has_capability() to make
the default role fallbacks and guest/nonloggedin roles work.

This commit also introduces the concept of having a magic
context next to the root context in $USER->access[ra], as

 $USER->access[ra][/1] = 1 (admin roleid)
 $USER->access[ra][/1:def] = 7 (loggedinuser roleid)

and has_cap_fromsess() now checks for that magic context
as well.
2007-09-19 07:02:57 +00:00
martinlanghoff
74ac5b66cb accesslib: has_capability() now works for the logged in user
With this commit, the new has_capability works for the logged
in user correctly.

 - load_all_capabilities() no longer calls load_user_capability()!
   6K dbqueries less on login... ;-)

 - When delving into a context we haven't loaded yet, we call
   get_user_access_bycontext()

 - Introduce: get_user_access_bycontext()

 - Several fixes in get_user_access_sitewide()
   (renamed from get_user_sitewide_access())

 - Fixes in has_cap_fromsess()

 - Introduce access_insess() to check if we have to call
   get_user_access_bycontext() for the context
2007-09-19 07:02:44 +00:00
martinlanghoff
7f97ea29bf accesslib: initial has_capability() rewrite
- has_capability() renamed has_capability_old() and we fallback
   when we cannot answer the question

 - has_capability() works great for the course-and-above contexts
   for the logged in user - does not touch the DB

 - works based on $USER->access which has a pretty compact view
   of the user's access rights...

TODO:

 - deal with contexts below the course - here we need to
   trigger the role-assignment and role-defs load when needed

 - deal with "other" contexts that hang from the system context

 - deal with global roleswitch, local roleswitch
2007-09-19 07:02:31 +00:00
martinlanghoff
a9bee37ea1 accesslib: Introducing get_user_sitewide_access($userid)
This function carefully fetches all the data needed to
handle site/category/course access for a given user
as cheaply as possible.

It currently takes 3 db queries.
2007-09-19 07:02:04 +00:00
martinlanghoff
1f3c9d097f accesslib: Introducing build_context_path()
which populates the context.path and context.depth fields
2007-09-19 07:01:27 +00:00
martinlanghoff
19bb8a0517 accesslib:get_child_contexts() reworked to use context.path
Using context.path, now get_child_contexts...

 - always takes 1 query
 - populated the context_cache
 - returns full records
 - when called with an category, it won't
   recurse into the children of courses

Also

 - All callers in accesslib changed to the new
   calling convention

A normal course page with a std blocks and a few
activities sees around 100 queries less with this patch.

Note: this commit is slightly different on HEAD/19 and on
MOODLE_18_STABLE, as groups-related tables have changed.
2007-09-19 06:52:34 +00:00
martinlanghoff
17b0efae11 accesslib: Introducing cleanup_contexts() and use it in cron
The newly minted cleanup_contexts() walks the context table
matching contexts with the tables they are referencing and
clearing any leftover contexts.
2007-09-19 06:50:53 +00:00
nicolasconnault
c421ad4b2e MDL-11233 Corrected typo in grader report lib, and added a second sort parameter for lastname and firstname sorts, to add consistency to result sets. Non-students no longer appear in the list 2007-09-13 13:44:35 +00:00
mattc-catalyst
38553f9754 MDL-10888: groupings - fix SQL error 2007-08-27 03:54:59 +00:00
skodak
dda6370707 MDL-10635 fixed incorrect capability value check in has_capability_including_child_contetxt() 2007-08-26 16:55:46 +00:00
skodak
47ba005d0d MDL-10995 course parents cache size now limited 2007-08-26 07:58:20 +00:00
moodler
5464c36277 Fixes for grade plugincapability names MDL-10989 2007-08-26 05:49:59 +00:00
skodak
3bf618ce0d MDL-10995 implemented caching of course and category parents - eliminates substantial number of db queries - mostly during login and on course page 2007-08-25 19:25:17 +00:00
skodak
5785266f9e MDL-10995 removing previous patch; testing a better one just now 2007-08-25 14:35:54 +00:00
skodak
8496a9c911 MDL-10995 improved capability_search():
* eliminated fetching of course - $COURSE used if id matches
* parent category structure is cached in static array
2007-08-25 12:22:15 +00:00
skodak
e6260a456b MDL-10635 improved performance of update_course_icon() and friends; fixed parameter of iseditting() - removed $userid which was not used and did not make much sense there anyway 2007-08-25 11:28:37 +00:00
skodak
c331cf23c5 MDL-10945 fixed block capability checks in switch role mode 2007-08-22 19:20:20 +00:00
skodak
5bf243d131 MDL-10383 - groups/groupings refactoring nearly finished ;-) 2007-08-16 11:06:48 +00:00
toyomoyo
baea72ec48 some changes for better capabilities list display 2007-08-16 08:48:53 +00:00
skodak
2c386f82e5 MDL-10383 - deprecated get_groups(), user_group() and ismember() 2007-08-15 20:21:01 +00:00
poltawski
7e874772a3 MDL-10573 - Added a capability for viewing blocks, this allows role-based control of block
display.

Changed context capability check so that CONTEXT_BLOCK capabilities can also come from the
moodle core capability definitions
2007-08-13 10:08:15 +00:00
poltawski
be23993798 MDL-10624 Reverting forum part of last commit - it wasn't needed, I wasn't testing
correctly. merged from 18_STABLE
2007-08-06 19:17:36 +00:00
poltawski
87c2d37d82 Fixed typo in previous commit 2007-08-06 18:47:57 +00:00
poltawski
2515adf9ea MDL-9431 & MDL-10624 - we're not removing some tracking records from the
database when we unassign roles - remove forum_subscriptions & user_lastaccess

Merged from MOODLE_18_STABLE
2007-08-06 18:45:35 +00:00
stronk7
6cdd0f9c93 Adding Id tag + copyright notice.
Merged from MOODLE_18_STABLE
2007-08-06 17:55:44 +00:00
toyomoyo
c345bb584a MDL-10679, improvement to context_rel table and load_user_capability 2007-08-02 08:28:29 +00:00
toyomoyo
3527464679 when unassign users in course, if user has no more course:view capability left, he should be removed from all groups in course 2007-07-27 05:43:05 +00:00
skodak
89bd8357e9 MDL-10579 capabilities for grade export plugins 2007-07-24 08:51:45 +00:00
mattc-catalyst
cd54510d42 lib/accesslib: Performance optimisation
- On postgres query time drops from ~600ms to ~35ms in some
  instances, in other instances performance is around the same
  as old the implementation.


Author: Matt Clarkson <mattc@catalyst.net.nz>
2007-07-20 04:05:34 +00:00
toyomoyo
60ace1e114 merged fix for MDL-10149, preventing the deletion of the last admin role 2007-07-19 05:19:05 +00:00
toyomoyo
69b0088cd9 merged fix for MDL-10461, timemodied in role assignments not preserved 2007-07-19 03:37:53 +00:00
skodak
454cf87189 MDL-10421 $fields= typo 2007-07-11 17:27:46 +00:00
toyomoyo
52bb13dc9f adding group support for get_role_users 2007-07-09 06:22:56 +00:00
toyomoyo
898d7119f0 round up enrolment to day, truncate the rest MDL-10181 2007-07-04 02:26:36 +00:00
tjhunt
d53587d822 MDL-10250 - Extend get_users_by_capability to have a $useviewallgroups parameter. 2007-06-26 16:16:46 +00:00
toyomoyo
2f2d4fb53f adding limits to get_role_users() to enable extracting specific users 2007-06-22 09:03:03 +00:00
tjhunt
b5c2f0afff Fix typo spotted by Eclipse. 2007-06-12 13:47:21 +00:00
tjhunt
e765b5d377 Improve doc comments on get_context_* funcitions. 2007-06-12 11:11:42 +00:00
jamiesensei
7d8ea28668 MDL-9891 new 'clonepermissionsfrom' key in access.php 2007-05-27 04:53:02 +00:00
toyomoyo
ce34ed3a76 fix for MDL-9137, adding support for gradebook plugins for db, cron, events, permission structures etc 2007-05-24 02:16:31 +00:00
jamiesensei
cd26d8e047 MDL-9857 "more options in print_context function" 2007-05-22 10:09:22 +00:00
toyomoyo
9492291c82 some changes to events to make grade_added work 2007-05-15 03:19:01 +00:00
sam_marshall
3bb92bbe04 MDL-9382: Added fields and orderby parameters to get_user_capability_course, which allows for greatly improved performance in the case where you want more information about the courses. (However, the function does still basically suck.) 2007-05-14 12:11:47 +00:00
poltawski
c3d1fbe943 MDL-9726 - fixed phpdoc comment from MartinD's commit 2007-05-07 08:34:08 +00:00
toyomoyo
6ceebc1f32 merged fix for MDL-9656, blocks parents can be system context 2007-05-07 03:24:22 +00:00