28317 Commits

Author SHA1 Message Date
martinlanghoff
91d39e7392 user/index: switch to recordsets to use less memory
Memory usage was still high for long userlists. Use recordsets
to manage memory growth.

Note that we are still collecting a long long HTML table in memory
before we print it, so the footprint of the html itself is bit of an
issue.
2007-09-19 07:55:15 +00:00
martinlanghoff
b6ac3623ce user/index: Fetch participants' contexts with the search
With this patch, we fetch participants contexts in the main search
query. This cuts 1DBq per participant for the display.

Might fix MDL-11222 'global teacher viewing participants issues' where
we are getting OOM'd with many users.
2007-09-19 07:55:00 +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
aba5f469f6 accesslib: get_user_access_sitewide() was skipping rdefs
The SQL query that would fetch rdefs not associated with any ra was
not being executed. Duh! For example, a user with a teacher RA sitewide
would never be affected by a role override at the category
level, because it was not being loaded into accessdata.
2007-09-19 07:54:06 +00:00
martinlanghoff
53fb75dc1f accesslib: get_user_access_bycontext() fetches all relevant rdefs
get_user_access_bycontext() was narrowing down too much the rdefs it
was fetching. With this patch, it now correctly retrieves the rdefs for
new roles assigned in lower contexts, and also correctly retrieves
rdefs present in the course context (fixing MDL-11220).

This also means that we now do the job in 2 DB queries (instead of 3),
and we move a bit more data, but those rows are actually needed ;-)
2007-09-19 07:53:49 +00:00
martinlanghoff
37875ac5b7 calendar/lib: calendar_set_filters() use pre-fetched context and course recs
Showing the calendar block was causing 2 DB queries per course the
user is enrolled in. Instead, use the data available in the array that
is passed as a parameter, and spare the DB a ton of needless traffic.

Fixes MDL-11221 Calendar not using context stuff from get_my_courses

Author: Martin Dougiamas
2007-09-19 07:53:33 +00:00
martinlanghoff
853a093ec5 course/index: remove call to rebuild_context_rel()
Very last caller to rebuild_context_rel() and any XX_context_rel()
function. move_category() already takes care of calling
context_moved(), which does the required context.path maintenance.

Addresses MDL-11219
2007-09-19 07:53:17 +00:00
martinlanghoff
dd14fecfa4 accesslib upgrade: remove stray build_context_rel(), force path rebuild
Fixes problems during upgrades from 1.7x/1.8.x to mdl19-perf.
2007-09-19 07:53:00 +00:00
martinlanghoff
8f9a180282 weblib: build_navigation() try to avoid pointless capchecks
Prevent calls to has_capability() in build_navigation() from messing
with upgrades.

Most calls to has_capability() in weblib should be moved to the callers.
2007-09-19 07:52:42 +00:00
martinlanghoff
6b4d8c4d58 course/lib: print_course() fix bug when $course->managers was not set
Fix a thinko in a variable assignment that prevented us from grabbing
the correct roles as managers. Addresses Yu's report at
MDL-11182 admin shows up as teacher.
2007-09-19 07:52:27 +00:00
martinlanghoff
c7a8ec8cf0 accesslib: has_cap_fad() respect local-context-wins permissions rule
The initial implementation of has_cap_fad() just added the permission
values regardless of the locality of the context. This patch adds
support (read: fixes bug) for the "local context wins" rule.

Additionally, it removes a related bug where we were exiting early
if we found a CAP_PROHIBIT, ignoring the $doanything flag.
2007-09-19 07:52:06 +00:00
martinlanghoff
5b9e50caf0 course/lib: print_my_moodle() - ask get_my_courses() for the summary
get_my_courses() now defaults to a much leaner dataset, but accepts an
array of "additional" fields we want. So ask nicely for the summary,
so that we can print_course() later with it.
2007-09-19 07:51:50 +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
5f6b9c09b7 index.php: drop unused $hidesitecourse parameter when calling print_courses()
And this is the only user of print_courses() that mentions it
explicitly. Other callers have been checked and don't need or use the
sitecourse.
2007-09-19 07:51:02 +00:00
martinlanghoff
6c54240a61 course/lib: print_courses() drop $hidesitecourse parameter
The $hidesitecourse and related code seem to be dead code. An audit of
the callers did not turn up any interesting/valid use of it.
2007-09-19 07:50:41 +00:00
martinlanghoff
49cd4d7934 Revert "course/lib: print_courses() - no need to worry about sitecourse"
This reverts commit d7816749a4ceda352a2fac6e82d7f02f435473ed.
2007-09-19 07:50:28 +00:00
martinlanghoff
1d28d87b35 accesslib - Ensure newly-created categories have a context
New categories need a context immediately, and for top-level
categories, they also need to taint the "root" context to trigger
a reload of $USER->access.

This fixes problems with creation of initial courses(MDL-11178),
duplicate misc categories, etc.
2007-09-19 07:50:05 +00:00
martinlanghoff
015e19287b Revert "textlib: Don't require_once() class.t3lib_div.php which we never use"
Turns out class.t3lib_cs.php depends on class.t3lib_div.php. Will drop
the two commits before we go into HEAD.

This reverts commit 5768bf6fb4dfa334dc81a80d26111904c4d13abd.
2007-09-19 07:49:49 +00:00
martinlanghoff
1dcf763428 accesslib: get_user_access_bycontext() remove 2 unused var declarations (trivial) 2007-09-19 07:49:35 +00:00
martinlanghoff
55c47e48a9 course/lib: print_courses() - no need to worry about sitecourse
get_courses_wmanagers() excludes the sitecourse, so we no longer
check for it. And check explicitly for an empty course array.
2007-09-19 07:49:23 +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
c9e42aaa99 course/index: Bring back Petr's MDL-9647 simplify dealing with headers/footers in admin sections
I had mistakenly reverted some of Petr's changes.

Fixes MDL-11179 19PERF: Notice on /course/index.php as admin
2007-09-19 07:48:56 +00:00
martinlanghoff
987e7eb19a accesslib: is_siteadmin() bugfixes
Fixed two horrid bugs in is_siteadmin(). Both userid and the check for
matching cpabilities lines were wrong.
2007-09-19 07:48:43 +00:00
martinlanghoff
9f560a0ccb accesslib: fix SQL CAST()s to work on MySQL and PostgreSQL
CAST() target types aren't very portable. Use DECIMAL which works
for MySQL and Pg.

DECIMAL does seem to be supported in Oracle - but the syntax seems
different. We may still need a compat function.
2007-09-19 07:48:31 +00:00
martinlanghoff
9264620341 accesslib: remove has_capability_including_child_contexts()
No code is calling it, and it never appeared in any release.
2007-09-19 07:48:19 +00:00
martinlanghoff
0df35335ba moodlelib: isediting() uses $PAGE->user_allowed_editing(), drop editcourseallowed()
With this commit, isediting() checks with the page if the user is
allowed editing. And as the last caller of editcourseallowed() is gone,
remove it.
2007-09-19 07:48:03 +00:00
martinlanghoff
f7016edcb9 index: use $PAGE->edit_course_allowed() instead of editcourseallowed()
$PAGE->edit_course_allowed() has been reworked and is faster/smarter
than editcourseallowed(). It can also be made more specific on a
per-page-type basis.
2007-09-19 07:47:49 +00:00
martinlanghoff
9a55125ef6 blocks/admin_tree: applicable_formats() is called as a class method
Can't find it documented anywhere, but applicable_formats() is only
ever called as a class method, so it cannot say $this. Instead, say
block_admin_tree::has_admin_caps().
2007-09-19 07:47:38 +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
41709a387f accesslib: replace join() and sql_intarray_to_in() with implode()
implode() is the PHP-ish way of saying this. join() is too Perlish and
may get confused (or misgrepped) with a SQL JOIN.
2007-09-19 07:47:11 +00:00
martinlanghoff
0c13a90844 textlib: Don't require_once() class.t3lib_div.php which we never use
The largest of the 2 typo3 libs we ship in Moodle is never used. So
don't even parse it.

This takes Moodle's "default homepage" from 1.8MB to 1.6MB of PHP.
Tiny, but every bit helps...
2007-09-19 07:46:54 +00:00
martinlanghoff
2a2057736e moodlelib: moodle_request_shutdown() prints included files
If MDL_PERFINC is defined, we now print to errorlog a listing
of the files included, their size, and then a total size.

The total size isn't the most important metric, though it does give us
a good idea of how much PHP the PHP engine is parsing for us. The main
cost is still in the seeks involved.

Even when using precompilers -- our best-case scenario -- each include
or require forces at least 2 stat()s to compare timestamps in the php
file vs the precompiled file. If the working set fits in buffers we are
fine, but our 60+ stat() calls per page is quite a bit.
2007-09-19 07:46:39 +00:00
martinlanghoff
0146bd4190 blocks/admin_tree: Show the block if some admin privs present...
Dan Poltawski said:
> Previously users with different permissions could have granular
> access to the admin menu for the items they have access to, so
> limiting to only users with moodle/site:config would break that.
> Although I agree that that menu is slowww to render and needs
> fixing. Perhaps permissions for the various elements could be
> gathered and checked first

This commit addresses the problem checking for all the caps that are
mentioned by code in /admin (according to grep, at least). Some light
testing with the "moodle/user:create" seems to work properly.

This burdens us with maintaining the list in has_admin_caps() -- less
than ideal, but easier than rewriting /admin.
2007-09-19 07:46:24 +00:00
martinlanghoff
18b1d84820 accesslib upgrade: admin/upgradesettings may need to load_all_capabilities()
This shouldn't happen, but sometimes admin/upgradesettings needs to
reload_all_capabilities(). So do it.
2007-09-19 07:46:12 +00:00
martinlanghoff
f667ecfe3d accesslib 1.9 upgrade: homepage check to see if we need to upgrade
This check adds a DB query _only when the upgrade is pending_. So
for a few minutes at the most.
2007-09-19 07:45:45 +00:00
martinlanghoff
c24f4599c3 accesslib rework: Upgrade block to populate context.path and friends
Note: this upgrade changes how accesslib works.
2007-09-19 07:42:42 +00:00
martinlanghoff
394074424a accesslib: Introducing is_siteadmin() to reliably check for siteadmins
is_siteadmin checks a few key capabilities to suss out if the user is
an admin. The main virtue of the function is that it does not use
the accesslib infrastructure -- it reads directly from the DB, which
is useful for the 1.9 accesslib upgrade.
2007-09-19 07:30:09 +00:00
martinlanghoff
67ab1aecfb admin/index: Populate the context path JIT for the new admin user
With this call to build_context_path() the admin rights of the new
user are loaded just before they are first needed.
2007-09-19 07:29:55 +00:00
martinlanghoff
d4bec85829 accesslib: get_user_courses_bycap() fix to deal with empty $order
If we are passed an empty string for $order, still create valid
SQL. Some callers in 1.9 seem to not care about order, passing
an explicit ''. Shocking! ;-)
2007-09-19 07:29:43 +00:00
martinlanghoff
1e460fdfc2 accesslib: remove references to deprecated context_rel table and insert_context_rel()
These references to the deprecated functions were erroring out. Remove
them.

Note however that other role related cleanups done as part of
MDL-10679 "improvement to context_rel table and load_user_capability()"
are kept.
2007-09-19 07:29:31 +00:00
martinlanghoff
ad72d0d702 admin/cron: move accesslib stuff to occasional cleanups, add build_context_path()
The accesslib cleanups aren't needed every 5. Also, add
build_context_path() and instructions on how to run it
as build_context_path(true) to force a path rebuild.
2007-09-19 07:29:20 +00:00
martinlanghoff
ad4c7473a9 accesslib: build_context_path() is now much much cheaper
We now populate the context.path only where it's empty,
this means that we take 0.15s instead of 0.6s. More importantly,
we avoid thrashing the DB's indexes pointlessly.

We also support Oracle and its dirty hack here.

And the function now has a $force parameter that can be used to
actually overwrite the paths/depths in case they've been corrupted.
2007-09-19 07:29:07 +00:00
martinlanghoff
2960a5525a backup/restore_form.html: tiny XHTML compliance fix
There is something _weird_ about the table setup on this page
and I cannot figure it out. This change "fixes" it in that
FF stops complaining.

However, the fix looks very broken to me.
2007-09-19 07:28:54 +00:00
martinlanghoff
44f1636ee2 datalib: get_categories() - remove PostgreSQL-ism 2007-09-19 07:28:43 +00:00
martinlanghoff
a72921ae68 accesslib: Use sql_compat() to remove unportable PostgreSQL-isms 2007-09-19 07:28:31 +00:00
martinlanghoff
2dff3a0681 accesslib: get_assignable_roles() reworked to be constant-queries
get_assignable_roles() was calling user_can_assign() (cost of 1~2 DBq)
once-per-role. Instead, we can do a single DB query that answers
all our questions in one go.

On a Moodle w 8 roles defined, saves 19 DB queries for the course page
for teachers/admins.

NOTE NOTE NOTE! With this patch we drop the insane strip/escape bit.
Only the caller knows if this is for display on html or for other uses,
so we'll be true and not mangle the data.

A review of all callers in 1.8 shows no problem - the strings were being
strip/escaped already.
2007-09-19 07:27:46 +00:00
martinlanghoff
dfbf98cdb3 course/index: minor context-related fixes
- The code uses the system context a lot. Declare
   $sysctx at the top and use it.

 - If the category has a context property, use it
   (saves 1 DB query per category displayed)

The DB costs of this page in editing mode are

 - ~100 DB queries for fix_course_sortorder()

 - ~50 DB queries for the categories listing

If we rewrite both to lose the recursion, we could resolve the
page in perhaps 5 DBq.
2007-09-19 07:27:31 +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