455 Commits

Author SHA1 Message Date
martinlanghoff
656418b179 MDL-11180 datalib: get_courses() - grab the course context as part of the select
This speeds up course & category listing enormously - cutting 2500 DB queries
for a site with 2500 courses. It's the power of the JOIN...
2008-02-26 21:48:08 +00:00
moodler
f191a887c6 MDL-12294 merge parentlang 2008-02-26 07:29:09 +00:00
skodak
585385278c MDL-13483 found two more native php mail() commands; merged from MOODLE_19_STABLE 2008-02-25 14:05:06 +00:00
skodak
c7e6b7e462 MDL-13399, MDL-13614 fixed regression caused by last commit; merged from MOODLE_19_STABLE 2008-02-23 19:29:25 +00:00
skodak
7007049315 MDL-13399 prevent ambiguous column names in get_my_courses; merged from MOODLE_19_STABLE 2008-02-18 20:14:16 +00:00
skodak
ac0b1a1987 MDL-13155 reworked get_all_instances_in_course() and get_all_instances_in_courses(), based on patch by Tim; merged from MOODLE_19_STABLE 2008-02-05 21:34:58 +00:00
skodak
b4619aba72 MDL-12945 disabled mods are not returned from get_course_mods() anymore, the results are used in scheduled backup and other parts that do not expect disabled mods; merged from MOODLE_19_STABLE 2008-02-01 07:33:37 +00:00
skodak
dd97c32868 MDL-12945 a slightly bigger patch for performance in recent activity and various group related issues + some other fixes - see list of subtasks in tracker; merged from MOODLE_19_STABLE 2008-01-24 20:33:50 +00:00
martinlanghoff
c26ecb1a29 datalib: get_admins() - Rewrite to avoid get_users_by_capability()
get_admins() and get_admin() were counting on
get_users_by_capability() returning a role-assignment id to pick the
"primary" admin account. With the get_users_by_capability() rewrite,
we no longer have an RA id to clearly blame for the capability.

So, rewrite get_admins() based on the known-good SQL used in
is_siteadmin().

MDL-12452
2008-01-06 23:24:50 +00:00
stronk7
0f62a5b5bb Better behaviour for "-" course searches under MSSQL and Oracle. MDL-7312 ; merged from 19_STABLE 2008-01-01 12:03:00 +00:00
stronk7
a599aeebe5 Prevent some debugging notices, cast to object before inserting. Merged from 19_STABLE 2007-12-31 15:20:02 +00:00
tjhunt
3d96cba76a Improve PHP doc comments. 2007-12-12 17:10:48 +00:00
martinlanghoff
1d854cec5a datalib: get_logs_user*() - fix invalid SQL - MDL-12426
Oracle does not accept column labels in the GROUP BY section -
get_logs_usercourse() and get_logs_userday() were computing the
day/hours column and using it in the GROUP BY. The compatible fix
is to reproduce the same computation in the GROUP BY section.

Credit for the fix goes to Dennis Rochford <Dennis.Rochford@usq.edu.au>.
2007-12-04 06:26:10 +00:00
skodak
cd1edf9e8a MDL-12101 cleanup/fixing/refactoring of user bulk operation and admin user browsing 2007-11-13 08:43:20 +00:00
tjhunt
5354679f77 Fix typo. Merged from MOODLE_19_STABLE. 2007-10-25 14:30:07 +00:00
toyomoyo
9f06454655 MDL-11893, email admin when add_to_log() fails 2007-10-25 04:02:41 +00:00
skodak
03cedd6283 MDL-11432 eliminated majority of RecordCount uses, added several missing rs_close() - this should help improve perf on some platforms - Eloy says ;-) 2007-10-10 12:19:27 +00:00
stronk7
115a43113a ANSI join ON clauses should contain only the join condition. Also,
added prefix to the ORDER BY to prevent duplicate names.
2007-10-08 17:42:46 +00:00
moodler
5b1dbd5cd7 Some SQL fixes to avoid putting 'quotes' around integers (performance) 2007-10-05 13:34:28 +00:00
skodak
d75731c6ac prevent returning of invalid array from get_course_managers() 2007-10-03 22:26:05 +00:00
stronk7
59bef7283d Moving 3 functions from datalib to deprecatedlib. Only used
by admin/cron.php. First step of MDL-11571 and MDL-11487
2007-10-03 16:31:20 +00:00
moodler
1afb11e70b Fixed longtimenosee unenrolments. user_lastaccess and role_assignments were growing with uneccessary entries, to the point where memory limits were reached and in the end NO unenrolments were happening at all.
See  MDL-11571
2007-10-03 12:24:06 +00:00
tjhunt
3b0ee367a7 MDL-11466 - failing to check for the case $rs = false in the accesslib performance improvements. Credit for the fix goes to Gareth Morgan. 2007-09-26 21:31:54 +00:00
tjhunt
8d503f7557 Get rid of duplicate $Id$ tags. 2007-09-26 10:11:13 +00:00
nicolasconnault
bfbfdb5350 MDL-11350 allowvisiblecoursesinhiddencategories was not used fully in the determination of the course's visibility 2007-09-20 13:15:26 +00:00
toyomoyo
05a71b3341 change restore code to use the more efficient get_user_courses_bycap 2007-09-20 09:16:49 +00:00
tjhunt
1ced9d7b73 MDL-10903 - Wrong capability checked in get_all_instances_in_course should be moodle/course:viewhiddenactivities, not moodle/course:viewhiddencourses. Merged from MOODLE_18_STABLE. 2007-09-19 17:06:31 +00:00
martinlanghoff
45ea1afb16 accesslib: make_context_subobj() now expects ctxlevel, and fix all callers
make_context_subobj() was not providing a contextlevel property, and
no callers fetched the field. This comes from its humble origins where
it was only ever called for course objects. These days it's used in
many other situations, so this patch DTRT and

 - fixes make_context_subobj() expect a cxtlevel and turn it into
   contextlevel

 - fixes all callers (accesslib, datalib) to provide it
2007-09-19 07:54:37 +00:00
martinlanghoff
b1cff118c7 datalib:get_courses_wmanagers() handle empty $CFG->coursemanager more gracefully
Having no roles set as coursemanager is a valid setting.
get_courses_wmanagers() should not produce invalid SQL on it...
actually, it should not even try to get the course managers.
2007-09-19 07:54:23 +00:00
martinlanghoff
bbfed0ec61 datalib: get_my_courses() honour $fields array
If the caller passes a fields array, then merge it as we say we will do.
2007-09-19 07:51:36 +00:00
martinlanghoff
b9e9491a89 accesslib: get_my_courses() fix when called when empty sort
get_my_courses() was failing if called with an empty sortorder on a
cached courselist. Fix.
2007-09-19 07:51:19 +00:00
martinlanghoff
e89f157b0a datalib: get_courses_wmanagers() exclude the sitecourse
Should never return the sitecourse - so we exclude it explicitly.
2007-09-19 07:49:10 +00:00
martinlanghoff
2e159efb1c Revert "datalib: Introducing sql_intarray_to_in()"
We don't need sql_intarray_to_in(), use implode() instead.

This reverts commit 3ef7fc54d9df780c837c64a8ace1fc565d6d7744.
2007-09-19 07:47:26 +00:00
martinlanghoff
44f1636ee2 datalib: get_categories() - remove PostgreSQL-ism 2007-09-19 07:28:43 +00:00
martinlanghoff
40fb8aa69a datalib: get_categories() returns context, supports !shallow
With this patch, get_categories() now adds a nice context
sub-object to the returned object, which means callers can
save DB traffic.

It now also supports "deep" retrievals, which means we can
rewrite the course categories display pages to avoid
costly recursion.
2007-09-19 07:27:20 +00:00
martinlanghoff
c5d13b689f datalib: fix_course_sortorder() - minor optimisation
Don't update fields unnecessarily. Cuts 3 DB queries per category
on course/index page (45 in a 15 category setup).

fix_course_sortorder() should be fixed to avoid recursion.
2007-09-19 07:27:08 +00:00
martinlanghoff
70f158789e datalib: Introducing get_courses_wmanagers() for print_courses() usage
For an efficient print_courses() we need to grab in a constant number
of queries...

 - course data
 - "course manager" role assignments
 - user records for the coursemanagers' fullname()

So here we do it in 2 DB queries. The 2nd one (grabbing RAs and user
records) can be expensive if we are dealing with a large number of
courses.

Which we shouldn't - When the number of courses is large the course
listing doesn't come this way anyway...
2007-09-19 07:26:42 +00:00
martinlanghoff
2ee469b3b8 datalib: add_to_log() fix a bug and better error handling
All the $db->Execute calls now do proper err handling, and send their
message to debugging().
2007-09-19 07:22:37 +00:00
martinlanghoff
2965f8fdb8 datalib: get_admin() - cache in a static var
get_admin is called a zillion times during cron, and is a tiny
bit of data we can safely keep around... so...

(shaves 2 queries per email we send!)
2007-09-19 07:22:01 +00:00
martinlanghoff
b00cb46b27 datalib: get_my_courses() now returns invisible courses if visible to $USER
So admins can see the appropriate user listing in the profile page.

In fact, probably _all_ the visibility checks should be done by callers.
Hmmm...
2007-09-19 07:21:35 +00:00
martinlanghoff
3511647c44 datalib:course_parent_visible() rework, remove category_parent_visible()
Reworked course_parent_visible() to always return in a constant
number of db queries (2 worst case) regardless of nesting depth.

The rewritten version has a small cache, but if you are going to
walk many courses, it's still 1~2 DB queries per category seen,
so the right thing to do is to check it in the caller, as seen
in get_my_courses().
2007-09-19 07:19:05 +00:00
martinlanghoff
82c62d1b17 datalib: get_my_courses() - add course visibility checks
Reworked gmc to perform the course visibility checks. These are
very cheap if $CFG->allowvisiblecoursesinhiddencategories is true.

However, where we have to enforce category visibility, it adds a bit
of work. In simple terms, it adds a DB query to read all the categories,
and extra checks to make sure we are doing the right thing WRT

 - course visibility   vs the permission to see hidden courses
 - category visibility vs the permission to see hidden categories

and still do it quickly.
2007-09-19 07:18:54 +00:00
martinlanghoff
8fe9c4de51 datalib: get_courses_search() remove dead code 2007-09-19 07:09:01 +00:00
martinlanghoff
2c64f65cd3 datalib: get_courses_search() learns to be smart about contexts...
Join against contexts, save bazillion context lookups...
2007-09-19 07:08:37 +00:00
martinlanghoff
679b617967 categories: Categories page and get_courses_page() - smarter about context
This patch saves 1600 context lookups on a 1600 course category. rcache
does help a bit with small categories, but on large setups, this is
not sustainable.

And it's not needed either. We have the data right at our fingertips.
Just get it when it's cheap...
2007-09-19 07:08:24 +00:00
martinlanghoff
c1b7a5e537 accesslib: introducing make_context_subobj() - and refactor callers
We had many copies of the subcontext building bit. Time to
abstract it, and fix callers...
2007-09-19 07:08:12 +00:00
martinlanghoff
fe3141e00b get_my_courses() - bugfix in sitewide-login-as support.
Oops. The supportfor login-as was buggy now with sitewide
loginas. Now works in both.
2007-09-19 07:07:34 +00:00
martinlanghoff
ae1555ae2e get_my_courses(): Support course-level login as
A walkthrough of course-login-as functionality shows that is
Just Works, except that get_my_courses() was showing all the
courses. So we fix it.

And cleanup load_all_capabilities() - things just work
transparently.
2007-09-19 07:07:21 +00:00
martinlanghoff
352f6f74fc get_my_courses() and get_user_courses_bycap() field handling and caching
- Field handling moves back to get_my_courses() and now we have
  almost all the fields that the old get_my_courses() did
  (except for summary, which is *huge*) so get_my_courses() asks
  for a lot of fields, but the get_user_courses_bycap() defaults
  are _much_ leaner now.

  I think this makes sense ;-)

- get_my_courses() now caches the course ids for the currently logged in
  user in $USER->mycourses -- as a _string_. This is magnitudes more efficient
  than having it as an array.

The cache makes a difference, but it's not very visible on
normal pageloads (with my courses block, for example).

However, over 100 iterations, for a user with 50 enrolments in a site
with 6K courses, we go from 4.3s to 0.6s. And the DB queries are *cheap*.

            $tt = microtime(true);
            for($n=0;$n<100;$n++) {
                get_my_courses($USER->id, 'sortorder ASC');
            }
            error_log("took " .  (microtime(true) - $tt));
2007-09-19 07:04:59 +00:00
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