562 Commits

Author SHA1 Message Date
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
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
41883f79ca datalib: Introducing sql_intarray_to_in()
Trivial function to turn an array of ints into a string
usable in an IN sql clause.
2007-09-19 07:01:53 +00:00
martinlanghoff
a9fcd13a77 datalib:add_to_log() - avoid schema lookups, pace updates to user and user_lastaccess
* All updates to user.lastaccess and user_lastaccess.timeaccess are paced to
60s of the last update on the same record -- this should reduce the heat
on those tables.

* Updates/inserts to user_lastaccess are down with raw SQL to avoid costly
schema lookups on every request.
2007-09-19 07:01:04 +00:00
martinlanghoff
d863419245 course/index: move orphan fixups to an optimised fix_coursecategory_orphans()
Move the fixups for orphan courses to the newly minted
fix_coursecategory_orphans() -- and optimise it to take only 1 dbquery for
the common case.

If we do find lots of orphans, we issue 2 updates per orphan.

This cuts down dbqueries drastically - we used to have 2x the number of
courses in the site.
2007-09-12 02:56:36 +00:00
martinlanghoff
f8ea60777c fix_course_sortorder(): fix breakage with large categories, saner error
Two improvements for fix_course_sortorder()

 - If the category has more courses than the shift range
   use a larger shift range to avoid overlapping with itself

 - If things do go wrong during the per-course sortorder updates,
   rollback and try and call ourselves with a 'safe' flag.

Still - far from perfect. Probably the global sortorder approach
is broken. The sanest way is to rework things to always join against
course_categories and order by the combined sortorders.
2007-09-12 02:56:16 +00:00
skodak
2d675a2331 MDL-11023 silence warnings in PHP 4.x - the last param was added in PHP 5.0.2; merged from MODOLE_18_STABLE 2007-08-29 20:20:10 +00:00
mattc-catalyst
d8c9d8a150 MDL-10888: - groupings - mod/scorm - updated to support groupings 2007-08-28 02:54:37 +00:00
mattc-catalyst
e683967738 MDL-10888: groupings - added function to get all grouping members, cleaned up some notices 2007-08-26 23:47:24 +00:00
mattc-catalyst
8a67b03fce MDL-10888: groupings - make get_all_instances_in_course respect groupmembersonly 2007-08-22 04:20:42 +00:00
thepurpleblob
39dc779aa9 MDL-10929:
User search will now additionally return users based on an exact match
to their username.
2007-08-21 10:36:46 +00:00
Martin Langhoff
13534ef716 cvsimport fixups 2007-08-29 13:10:11 +12:00
skodak
2c386f82e5 MDL-10383 - deprecated get_groups(), user_group() and ismember() 2007-08-15 20:21:01 +00:00
skodak
1d68419596 MDL-10383 - deprecated groups_members_from_sql and friends - we do not need them anymore because we reverted to 1.7 style groups in 1.9 2007-08-15 19:28:11 +00:00
stronk7
92b564f494 Change xmldb debugging to use the central debugging() function. 2007-08-12 15:58:08 +00:00
stronk7
42fa499221 Prevent one warning
Merged from MOODLE_18_STABLE
2007-08-04 18:48:35 +00:00
stronk7
5930cded47 Added space to perform correct N' queries under MSSQL. MDL-10423
(plus general whitespace clean)

Merged from MOODLE_18_STABLE
2007-08-02 23:39:28 +00:00
toyomoyo
bdf3bbd198 if limit is specified on first call, ignore it, retrieve all, so that we can cache all entries, but only return the required number of entries at the end 2007-07-23 08:56:26 +00:00
toyomoyo
182c21f139 making get_my_courses() respect $limit 2007-07-23 08:38:07 +00:00
stronk7
ae7dc0d1e0 New cross-db version of the big union query used by get_my_courses() function.
I've tested both the "IN" subquery and the "FROM" subquery and, under sites
with more courses, the "FROM" one seems to perform slightly better. MDL-9381

Merged from MOODLE_18_STABLE
2007-07-22 00:56:42 +00:00
toyomoyo
61f774e8f6 merged fix for MDL-10469, users with doanything has no courses showing 2007-07-18 07:02:54 +00:00
mjollnir_
808fae8f05 fixing a small syntax oddity that breaks get_my_courses in postgres. quoting " means escape table, not string 2007-07-14 19:36:59 +00:00
toyomoyo
0674ff6ca8 sql_concact() can handle more than 2 params, thanks Eloy 2007-07-04 02:03:47 +00:00
toyomoyo
0cdd512c17 taking out some redundant sql 2007-06-29 08:31:01 +00:00
toyomoyo
12e27a048d MDL-9283, fixing a broken SQL, thanks Arno 2007-06-29 08:23:31 +00:00
toyomoyo
6a61f741e6 testing patch for MDL-9238 Arnaud's patch 2007-06-27 09:07:47 +00:00
martinlanghoff
6c146b7d7f get_my_courses() if the parameters passed are identical to the defaults... MDL-7416
We are using the defaults then ;-)

Credits for spotting it go to Yu!
Blames for the thinko to MartinL
2007-05-16 23:19:15 +00:00
martinlanghoff
0f7caaf84f get_my_courses() - ensure we have groupmode, groupmodeforce in $d_fields - calendar/lib.php counts on it 2007-05-06 05:37:28 +00:00
martinlanghoff
4dbca99edf get_my_courses() - added optimisation for guest login
- was causing very slow page generation
2007-05-06 05:28:39 +00:00
martinlanghoff
e4271d740c get_my_courses() - tighten default fields - faster, risky
This makes get_my_courses() faster/lighter in 2 ways

 - We fetch a ton less data from the DB
 - We store a tone less data in the Session

In a test environment, with a student enrolled in  3 _empty_ courses
(just created, empty modinfo, etc), this shaves 50% off the session
size on-disk.

The problem is callers that may be expecting a given field to appear by
default. Next step: walk all callers...
2007-05-06 05:27:31 +00:00
martinlanghoff
601edb900e get_my_courses() - skip checks if we know the user has moodle/site:doanything and we are observing $doanything
Author: Martin Langhoff <martin@catalyst.net.nz>
2007-05-06 05:26:59 +00:00
martinlanghoff
5970ccfbaf get_my_courses(): tighten cache scheme - part 2
the tighter cache was fragile as we always edit $field
2007-05-06 05:26:04 +00:00
martinlanghoff
c6325ef155 get_my_courses(): tighten cache scheme
This tightens the rather lax caching mechanism that
cached regardless of parameters.

Thanks to Matt Clarkson for the heads-up...
2007-05-06 05:22:03 +00:00
toyomoyo
daaf61f40c merged fix for MDL-9617, performance issues in calendar 2007-05-04 05:25:49 +00:00
toyomoyo
115a622d8c merged MDL-9273 related fixes 2007-04-13 05:40:11 +00:00
toyomoyo
d5cf76e3ff merged fix for MDL-9238 2007-04-10 08:57:48 +00:00
toyomoyo
49860445a6 fix for MDL-8739, restore in course category 2007-04-03 09:19:09 +00:00
tjhunt
1aa7b31dd9 Make sure print_object output is always left-aligned. Also, make it look more like other debugging output. 2007-04-02 15:28:43 +00:00
toyomoyo
47bb1aed07 merged fix for MDL-9160, get_my_courses caching issues 2007-04-02 03:53:10 +00:00
skodak
7c3dab9f86 MDL-8759 reverted previous incorrect patch with unset($USER), fixed logging function instead; solves the broken language in forum cron too; merged from MOODLE_18_STABLE 2007-03-08 01:09:00 +00:00
vyshane
2327b9df74 Merged from 1.7. 2007-02-08 08:06:08 +00:00
stronk7
b5eb752394 First real test of the new rs_fetchXXX() functions. Applying it
to get_my_courses(). MDL-8134

Merged from MOODLE_17_STABLE
2007-01-29 00:17:25 +00:00
skodak
e8e0bb2d7b MDL-8096 - advanced edit now mostly works, though still some parts missing; RIP changeme user :-) 2007-01-25 11:03:33 +00:00