mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
Some improvements in efficiency of Recent Activity.
There is now a new field in forum_discussions which has the userid of the author in it. This saves a lookup every time to forum_posts. There is also some caching and rearrangement of the logic. It seems to work OK, I'm about to do some speed tests on moodle.org
This commit is contained in:
parent
da8079852c
commit
d05956ac9f
8 changed files with 80 additions and 19 deletions
|
@ -128,6 +128,7 @@
|
||||||
fwrite ($bf,full_tag("ID",6,false,$for_dis->id));
|
fwrite ($bf,full_tag("ID",6,false,$for_dis->id));
|
||||||
fwrite ($bf,full_tag("NAME",6,false,$for_dis->name));
|
fwrite ($bf,full_tag("NAME",6,false,$for_dis->name));
|
||||||
fwrite ($bf,full_tag("FIRSTPOST",6,false,$for_dis->firstpost));
|
fwrite ($bf,full_tag("FIRSTPOST",6,false,$for_dis->firstpost));
|
||||||
|
fwrite ($bf,full_tag("USERID",6,false,$for_dis->userid));
|
||||||
fwrite ($bf,full_tag("ASSESSED",6,false,$for_dis->assessed));
|
fwrite ($bf,full_tag("ASSESSED",6,false,$for_dis->assessed));
|
||||||
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$for_dis->timemodified));
|
fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$for_dis->timemodified));
|
||||||
//Now print posts to xml
|
//Now print posts to xml
|
||||||
|
|
|
@ -84,6 +84,19 @@ function forum_upgrade($oldversion) {
|
||||||
table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
|
table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2004011404) {
|
||||||
|
table_column("forum_discussions", "", "userid", "integer", "10", "unsigned", "0", "", "firstpost");
|
||||||
|
|
||||||
|
if ($discussions = get_records_sql("SELECT d.id, p.userid
|
||||||
|
FROM {$CFG->prefix}forum_discussions as d,
|
||||||
|
{$CFG->prefix}forum_posts as p
|
||||||
|
WHERE d.firstpost = p.id")) {
|
||||||
|
foreach ($discussions as $discussion) {
|
||||||
|
update_record("forum_discussions", $discussion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ CREATE TABLE prefix_forum_discussions (
|
||||||
forum int(10) unsigned NOT NULL default '0',
|
forum int(10) unsigned NOT NULL default '0',
|
||||||
name varchar(255) NOT NULL default '',
|
name varchar(255) NOT NULL default '',
|
||||||
firstpost int(10) unsigned NOT NULL default '0',
|
firstpost int(10) unsigned NOT NULL default '0',
|
||||||
|
userid int(10) unsigned NOT NULL default '0',
|
||||||
assessed tinyint(1) NOT NULL default '1',
|
assessed tinyint(1) NOT NULL default '1',
|
||||||
timemodified int(10) unsigned NOT NULL default '0',
|
timemodified int(10) unsigned NOT NULL default '0',
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
|
|
|
@ -27,11 +27,23 @@ function forum_upgrade($oldversion) {
|
||||||
table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
|
table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2004011404) {
|
||||||
|
table_column("forum_discussions", "", "userid", "integer", "10", "unsigned", "0", "", "firstpost");
|
||||||
|
|
||||||
|
if ($discussions = get_records_sql("SELECT d.id, p.userid
|
||||||
|
FROM {$CFG->prefix}forum_discussions as d,
|
||||||
|
{$CFG->prefix}forum_posts as p
|
||||||
|
WHERE d.firstpost = p.id")) {
|
||||||
|
foreach ($discussions as $discussion) {
|
||||||
|
update_record("forum_discussions", $discussion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ CREATE TABLE prefix_forum_discussions (
|
||||||
forum integer NOT NULL default '0',
|
forum integer NOT NULL default '0',
|
||||||
name varchar(255) NOT NULL default '',
|
name varchar(255) NOT NULL default '',
|
||||||
firstpost integer NOT NULL default '0',
|
firstpost integer NOT NULL default '0',
|
||||||
|
userid integer NOT NULL default '0',
|
||||||
assessed integer NOT NULL default '1',
|
assessed integer NOT NULL default '1',
|
||||||
timemodified integer NOT NULL default '0'
|
timemodified integer NOT NULL default '0'
|
||||||
);
|
);
|
||||||
|
|
|
@ -386,6 +386,11 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
|
||||||
|
|
||||||
$strftimerecent = get_string("strftimerecent");
|
$strftimerecent = get_string("strftimerecent");
|
||||||
|
|
||||||
|
$isteacheredit = isteacheredit($course->id);
|
||||||
|
$mygroupid = mygroupid($course->id);
|
||||||
|
|
||||||
|
$groupmode = array(); /// To cache group modes
|
||||||
|
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
//Get post info, I'll need it later
|
//Get post info, I'll need it later
|
||||||
$post = forum_get_post_from_log($log);
|
$post = forum_get_post_from_log($log);
|
||||||
|
@ -411,25 +416,19 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Check whether this is belongs to a discussion in a group that
|
/// Check whether this is belongs to a discussion in a group that
|
||||||
/// should not be accessible to the current user
|
/// should NOT be accessible to the current user
|
||||||
/// TEMPORARY: This algorithm is ridiculously cumbersome ...
|
|
||||||
/// There MUST be a better way of doing this...
|
if (!$isteacheredit) { /// Because editing teachers can see everything
|
||||||
if ($cm = get_coursemodule_from_instance("forum", $post->forum, $course->id)) {
|
if (!isset($cm[$post->forum])) {
|
||||||
$groupmode = groupmode($course, $cm);
|
$cm[$forum->id] = get_coursemodule_from_instance("forum", $forum->id, $course->id);
|
||||||
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
|
$groupmode[$forum->id] = groupmode($course, $cm[$forum->id]);
|
||||||
if (!isteacheredit($course->id)) {
|
}
|
||||||
if ($discussion = get_record("forum_discussions", "id", $post->discussion)) {
|
if ($groupmode($forum->id)) {
|
||||||
if ($firstpost = get_record("forum_posts", "id", $discussion->firstpost)) {
|
if ($mygroupid != forum_get_groupid_from_discussion($post->discussion, $course->id)) {
|
||||||
if ($group = user_group($course->id, $firstpost->userid)) {
|
|
||||||
if (mygroupid($course->id) != $group->id) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $heading) {
|
if (! $heading) {
|
||||||
print_headline(get_string("newforumposts", "forum").":");
|
print_headline(get_string("newforumposts", "forum").":");
|
||||||
|
@ -800,6 +799,34 @@ function forum_get_post_from_log($log) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function forum_get_firstpost_from_discussion($discussionid) {
|
||||||
|
/// Given a discussion id, return the first post from the discussion
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
return get_record_sql("SELECT p.*
|
||||||
|
FROM {$CFG->prefix}forum_discussions d,
|
||||||
|
{$CFG->prefix}forum_posts p
|
||||||
|
WHERE d.id = '$discussionid'
|
||||||
|
AND d.firstpost = p.id ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function forum_get_groupid_from_discussion($discussionid, $courseid) {
|
||||||
|
/// Given a discussion id, return the groupid of the first poster
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
if ($info = get_record_sql("SELECT gm.groupid as id
|
||||||
|
FROM {$CFG->prefix}forum_discussions d,
|
||||||
|
{$CFG->prefix}forum_posts p,
|
||||||
|
{$CFG->prefix}groups g,
|
||||||
|
{$CFG->prefix}groups_members gm
|
||||||
|
WHERE d.id = '$discussionid'
|
||||||
|
AND g.courseid = '$courseid'
|
||||||
|
AND gm.groupid = g.id
|
||||||
|
AND gm.userid = d.userid")) {
|
||||||
|
return $info->groupid;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
function forum_get_user_grades($forumid) {
|
function forum_get_user_grades($forumid) {
|
||||||
/// Get all user grades for a forum
|
/// Get all user grades for a forum
|
||||||
|
|
|
@ -199,6 +199,7 @@
|
||||||
$discussion->course = $restore->course_id;
|
$discussion->course = $restore->course_id;
|
||||||
$discussion->name = backup_todb($dis_info['#']['NAME']['0']['#']);
|
$discussion->name = backup_todb($dis_info['#']['NAME']['0']['#']);
|
||||||
$discussion->firstpost = backup_todb($dis_info['#']['FIRSTPOST']['0']['#']);
|
$discussion->firstpost = backup_todb($dis_info['#']['FIRSTPOST']['0']['#']);
|
||||||
|
$discussion->userid = backup_todb($dis_info['#']['USERID']['0']['#']);
|
||||||
$discussion->assessed = backup_todb($dis_info['#']['ASSESSED']['0']['#']);
|
$discussion->assessed = backup_todb($dis_info['#']['ASSESSED']['0']['#']);
|
||||||
$discussion->timemodified = backup_todb($dis_info['#']['TIMEMODIFIED']['0']['#']);
|
$discussion->timemodified = backup_todb($dis_info['#']['TIMEMODIFIED']['0']['#']);
|
||||||
|
|
||||||
|
@ -227,13 +228,18 @@
|
||||||
if ($rec) {
|
if ($rec) {
|
||||||
//Put its new firstpost
|
//Put its new firstpost
|
||||||
$discussion->firstpost = $rec->new_id;
|
$discussion->firstpost = $rec->new_id;
|
||||||
|
if ($post = get_record("forum_posts", "id", $discussion->firstpost)) {
|
||||||
|
$discussion->userid = $post->userid;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$discussion->firstpost = 0;
|
$discussion->firstpost = 0;
|
||||||
|
$discussion->userid = 0;
|
||||||
}
|
}
|
||||||
//Create temp discussion record
|
//Create temp discussion record
|
||||||
$temp_discussion->id = $newid;
|
$temp_discussion->id = $newid;
|
||||||
$temp_discussion->firstpost = $discussion->firstpost;
|
$temp_discussion->firstpost = $discussion->firstpost;
|
||||||
//Update discussion (only firstpost will be changed)
|
$temp_discussion->userid = $discussion->userid;
|
||||||
|
//Update discussion (only firstpost and userid will be changed)
|
||||||
$status = update_record("forum_discussions",$temp_discussion);
|
$status = update_record("forum_discussions",$temp_discussion);
|
||||||
//echo "Updated firstpost ".$old_firstpost." to ".$temp_discussion->firstpost."<br>"; //Debug
|
//echo "Updated firstpost ".$old_firstpost." to ".$temp_discussion->firstpost."<br>"; //Debug
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// This fragment is called by /admin/index.php
|
// This fragment is called by /admin/index.php
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
$module->version = 2004010500;
|
$module->version = 2004011404;
|
||||||
$module->cron = 60;
|
$module->cron = 60;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue