mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Trying a different tack for recent_activity since the old way was
still producing too much data and overflowing PHP memory on busier sites (eg moodle.org). Now, there are more database queries, which is unfortunate, but the data is much more specific, and no sorting needs to be done, so this is a performance boost. I don't know how these will cancel out ... my guess is that very small sites may be very slightly slower on the course page, but that large sites will be much faster. Let's see.
This commit is contained in:
parent
a54b8dd3af
commit
1b5910c4a5
103
course/lib.php
103
course/lib.php
@ -322,21 +322,17 @@ function print_recent_activity($course) {
|
||||
$timestart = $timemaxrecent;
|
||||
}
|
||||
|
||||
if (! $logs = get_records_select("log", "time > '$timestart' AND ".
|
||||
"course = '$course->id' AND ".
|
||||
"module <> 'user' AND ".
|
||||
"action <> 'view' AND ".
|
||||
"action <> 'view all' ", "time ASC")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Firstly, have there been any new enrolments?
|
||||
|
||||
$heading = false;
|
||||
$content = false;
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "course" and $log->action == "enrol") {
|
||||
|
||||
$logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND
|
||||
module = 'course' AND action = 'enrol'", "time ASC");
|
||||
|
||||
if ($logs) {
|
||||
foreach ($logs as $key => $log) {
|
||||
if (! $heading) {
|
||||
print_headline(get_string("newusers").":");
|
||||
$heading = true;
|
||||
@ -346,53 +342,48 @@ function print_recent_activity($course) {
|
||||
if (isstudent($course->id, $user->id)) {
|
||||
echo "<p><font size=1><a href=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a></font></p>";
|
||||
}
|
||||
unset($logs[$key]); // No further need for it
|
||||
}
|
||||
}
|
||||
|
||||
if (! $logs) {
|
||||
return;
|
||||
}
|
||||
// Next, have there been any modifications to the course structure?
|
||||
|
||||
// Next, have there been any changes to the course structure?
|
||||
$logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND
|
||||
module = 'course' AND action LIKE '% mod'", "time ASC");
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "course") {
|
||||
if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
|
||||
$info = split(" ", $log->info);
|
||||
$modname = get_field($info[0], "name", "id", $info[1]);
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $info[1];
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($info[0],$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
switch ($log->action) {
|
||||
case "add mod":
|
||||
$stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
|
||||
$changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
||||
break;
|
||||
case "update mod":
|
||||
$strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
|
||||
if (empty($changelist["$log->info"])) {
|
||||
$changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
||||
}
|
||||
break;
|
||||
case "delete mod":
|
||||
if (!empty($changelist["$log->info"]["operation"]) and
|
||||
$changelist["$log->info"]["operation"] == "add") {
|
||||
$changelist["$log->info"] = NULL;
|
||||
} else {
|
||||
$strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
|
||||
$changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($logs) {
|
||||
foreach ($logs as $key => $log) {
|
||||
$info = split(" ", $log->info);
|
||||
$modname = get_field($info[0], "name", "id", $info[1]);
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $info[1];
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($info[0],$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
switch ($log->action) {
|
||||
case "add mod":
|
||||
$stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
|
||||
$changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
||||
break;
|
||||
case "update mod":
|
||||
$strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
|
||||
if (empty($changelist["$log->info"])) {
|
||||
$changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
||||
}
|
||||
break;
|
||||
case "delete mod":
|
||||
if (!empty($changelist["$log->info"]["operation"]) and
|
||||
$changelist["$log->info"]["operation"] == "add") {
|
||||
$changelist["$log->info"] = NULL;
|
||||
} else {
|
||||
$strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
|
||||
$changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($logs[$key]); // No further need for it
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,19 +402,17 @@ function print_recent_activity($course) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! $logs) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now display new things from each module
|
||||
|
||||
$mods = get_list_of_plugins("mod");
|
||||
|
||||
foreach ($mods as $mod) {
|
||||
$isteacher = isteacher($course->id);
|
||||
|
||||
foreach ($mods as $mod) { // Each module gets it's own logs and prints them
|
||||
include_once("$CFG->dirroot/mod/$mod/lib.php");
|
||||
$print_recent_activity = $mod."_print_recent_activity";
|
||||
if ($logs and function_exists($print_recent_activity)) {
|
||||
$modcontent = $print_recent_activity($logs, isteacher($course->id));
|
||||
if (function_exists($print_recent_activity)) {
|
||||
$modcontent = $print_recent_activity($course, $isteacher, $timestart);
|
||||
if ($modcontent) {
|
||||
$content = true;
|
||||
}
|
||||
|
@ -183,29 +183,31 @@ function assignment_cron () {
|
||||
return true;
|
||||
}
|
||||
|
||||
function assignment_print_recent_activity(&$logs, $isteacher=false) {
|
||||
function assignment_print_recent_activity($course, $isteacher, $timestart) {
|
||||
global $CFG;
|
||||
|
||||
$content = false;
|
||||
$assignments = NULL;
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "assignment") {
|
||||
if ($log->action == "upload") {
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $log->info;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
$assignments[$log->info] = assignment_log_info($log);
|
||||
$assignments[$log->info]->time = $log->time;
|
||||
$assignments[$log->info]->url = $log->url;
|
||||
}
|
||||
}
|
||||
unset($logs[$key]); // No longer need this record
|
||||
if (!$logs = get_records_select("log", "time > '$timestart' AND ".
|
||||
"course = '$course->id' AND ".
|
||||
"module = 'assignment' AND ".
|
||||
"action = 'upload' ", "time ASC")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($logs as $log) {
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $log->info;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
$assignments[$log->info] = assignment_log_info($log);
|
||||
$assignments[$log->info]->time = $log->time;
|
||||
$assignments[$log->info]->url = $log->url;
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,10 +217,10 @@ function assignment_print_recent_activity(&$logs, $isteacher=false) {
|
||||
print_headline(get_string("newsubmissions", "assignment").":");
|
||||
foreach ($assignments as $assignment) {
|
||||
$date = userdate($assignment->time, $strftimerecent);
|
||||
echo "<P><FONT SIZE=1>$date - $assignment->firstname $assignment->lastname<BR>";
|
||||
echo "\"<A HREF=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
|
||||
echo "<p><font size=1>$date - $assignment->firstname $assignment->lastname<br>";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/assignment/$assignment->url\">";
|
||||
echo "$assignment->name";
|
||||
echo "</A>\"</FONT></P>";
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,59 +296,62 @@ function forum_user_complete($course, $user, $mod, $forum) {
|
||||
}
|
||||
}
|
||||
|
||||
function forum_print_recent_activity(&$logs, $isteacher=false) {
|
||||
function forum_print_recent_activity($course, $isteacher, $timestart) {
|
||||
global $CFG;
|
||||
|
||||
$heading = false;
|
||||
$content = false;
|
||||
|
||||
if (!$logs = get_records_select("log", "time > '$timestart' AND ".
|
||||
"course = '$course->id' AND ".
|
||||
"module = 'forum' AND ".
|
||||
"action LIKE 'add %' ", "time ASC")){
|
||||
return false;
|
||||
}
|
||||
|
||||
$strftimerecent = get_string("strftimerecent");
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "forum") {
|
||||
if ($log->action == "add post" or $log->action == "add discussion") {
|
||||
//Get post info, I'll need it later
|
||||
$post = forum_get_post_from_log($log);
|
||||
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $post->forum;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
if ($post) {
|
||||
$teacheronly = "";
|
||||
if ($forum = get_record("forum", "id", $post->forum) ) {
|
||||
if ($forum->type == "teacher") {
|
||||
if ($isteacher) {
|
||||
$teacheronly = "class=\"teacheronly\"";
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $heading) {
|
||||
print_headline(get_string("newforumposts", "forum").":");
|
||||
$heading = true;
|
||||
$content = true;
|
||||
}
|
||||
$date = userdate($post->modified, $strftimerecent);
|
||||
echo "<p $teacheronly><font size=1>$date - $post->firstname $post->lastname<br>";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/forum/$log->url\">";
|
||||
if ($log->action == "add discussion") {
|
||||
echo "<b>$post->subject</b>";
|
||||
foreach ($logs as $log) {
|
||||
//Get post info, I'll need it later
|
||||
$post = forum_get_post_from_log($log);
|
||||
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $post->forum;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
if ($post) {
|
||||
$teacheronly = "";
|
||||
if ($forum = get_record("forum", "id", $post->forum) ) {
|
||||
if ($forum->type == "teacher") {
|
||||
if ($isteacher) {
|
||||
$teacheronly = "class=\"teacheronly\"";
|
||||
} else {
|
||||
echo "$post->subject";
|
||||
continue;
|
||||
}
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
}
|
||||
if (! $heading) {
|
||||
print_headline(get_string("newforumposts", "forum").":");
|
||||
$heading = true;
|
||||
$content = true;
|
||||
}
|
||||
$date = userdate($post->modified, $strftimerecent);
|
||||
echo "<p $teacheronly><font size=1>$date - $post->firstname $post->lastname<br>";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/forum/$log->url\">";
|
||||
if ($log->action == "add discussion") {
|
||||
echo "<b>$post->subject</b>";
|
||||
} else {
|
||||
echo "$post->subject";
|
||||
}
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
unset($logs[$key]); // No longer need this record
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
@ -119,34 +119,36 @@ function journal_cron () {
|
||||
return true;
|
||||
}
|
||||
|
||||
function journal_print_recent_activity(&$logs, $isteacher=false) {
|
||||
function journal_print_recent_activity($course, $isteacher, $timestart) {
|
||||
global $CFG;
|
||||
|
||||
$content = false;
|
||||
$journals = NULL;
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "journal") {
|
||||
if ($log->action == "add entry" or $log->action == "update entry") {
|
||||
///Get journal info. I'll need it later
|
||||
$j_log_info = journal_log_info($log);
|
||||
if (!$logs = get_records_select("log", "time > '$timestart' AND ".
|
||||
"course = '$course->id' AND ".
|
||||
"module = 'journal' AND ".
|
||||
"(action = 'add entry' OR action = 'update entry')", "time ASC")){
|
||||
return false;
|
||||
}
|
||||
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $j_log_info->id;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
foreach ($logs as $log) {
|
||||
///Get journal info. I'll need it later
|
||||
$j_log_info = journal_log_info($log);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
if (!isset($journals[$log->info])) {
|
||||
$journals[$log->info] = $j_log_info;
|
||||
$journals[$log->info]->time = $log->time;
|
||||
$journals[$log->info]->url = $log->url;
|
||||
}
|
||||
}
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $j_log_info->id;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
if (!isset($journals[$log->info])) {
|
||||
$journals[$log->info] = $j_log_info;
|
||||
$journals[$log->info]->time = $log->time;
|
||||
$journals[$log->info]->url = $log->url;
|
||||
}
|
||||
unset($logs[$key]); // No longer need this record
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,10 +158,10 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {
|
||||
print_headline(get_string("newjournalentries", "journal").":");
|
||||
foreach ($journals as $journal) {
|
||||
$date = userdate($journal->time, $strftimerecent);
|
||||
echo "<P><FONT SIZE=1>$date - $journal->firstname $journal->lastname<BR>";
|
||||
echo "\"<A HREF=\"$CFG->wwwroot/mod/journal/$journal->url\">";
|
||||
echo "<p><font size=1>$date - $journal->firstname $journal->lastname<br>";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/journal/$journal->url\">";
|
||||
echo "$journal->name";
|
||||
echo "</A>\"</FONT></P>";
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,19 +187,6 @@ function quiz_user_complete($course, $user, $mod, $quiz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function quiz_print_recent_activity(&$logs, $isteacher=false) {
|
||||
/// Given a list of logs, assumed to be those since the last login
|
||||
/// this function prints a short list of changes related to this module
|
||||
/// If isteacher is true then perhaps additional information is printed.
|
||||
/// This function is called from course/lib.php: print_recent_activity()
|
||||
|
||||
global $CFG;
|
||||
|
||||
$content = "";
|
||||
|
||||
return $content; // True if anything was printed, otherwise false
|
||||
}
|
||||
|
||||
function quiz_cron () {
|
||||
/// Function to be run periodically according to the moodle cron
|
||||
/// This function searches for things that need to be done, such
|
||||
|
@ -100,29 +100,31 @@ function survey_user_complete($course, $user, $mod, $survey) {
|
||||
}
|
||||
}
|
||||
|
||||
function survey_print_recent_activity(&$logs, $isteacher=false) {
|
||||
function survey_print_recent_activity($course, $isteacher, $timestart) {
|
||||
global $CFG;
|
||||
|
||||
$content = false;
|
||||
$surveys = NULL;
|
||||
|
||||
foreach ($logs as $key => $log) {
|
||||
if ($log->module == "survey") {
|
||||
if ($log->action == "submit") {
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $log->info;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
$surveys[$log->id] = survey_log_info($log);
|
||||
$surveys[$log->id]->time = $log->time;
|
||||
$surveys[$log->id]->url = $log->url;
|
||||
}
|
||||
}
|
||||
unset($logs[$key]); // No longer need this record
|
||||
if (!$logs = get_records_select("log", "time > '$timestart' AND ".
|
||||
"course = '$course->id' AND ".
|
||||
"module = 'survey' AND ".
|
||||
"action = 'submit' ", "time ASC")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($logs as $log) {
|
||||
//Create a temp valid module structure (course,id)
|
||||
$tempmod->course = $log->course;
|
||||
$tempmod->id = $log->info;
|
||||
//Obtain the visible property from the instance
|
||||
$modvisible = instance_is_visible($log->module,$tempmod);
|
||||
|
||||
//Only if the mod is visible
|
||||
if ($modvisible) {
|
||||
$surveys[$log->id] = survey_log_info($log);
|
||||
$surveys[$log->id]->time = $log->time;
|
||||
$surveys[$log->id]->url = $log->url;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,10 +134,10 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
|
||||
print_headline(get_string("newsurveyresponses", "survey").":");
|
||||
foreach ($surveys as $survey) {
|
||||
$date = userdate($survey->time, $strftimerecent);
|
||||
echo "<P><FONT SIZE=1>$date - $survey->firstname $survey->lastname<BR>";
|
||||
echo "\"<A HREF=\"$CFG->wwwroot/mod/survey/$survey->url\">";
|
||||
echo "<p><font size=1>$date - $survey->firstname $survey->lastname<br>";
|
||||
echo "\"<a href=\"$CFG->wwwroot/mod/survey/$survey->url\">";
|
||||
echo "$survey->name";
|
||||
echo "</A>\"</FONT></P>";
|
||||
echo "</a>\"</font></p>";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user