Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  - better checking of data before processing
  - used logs are removed to avoid re-processing by other modules
  • Loading branch information
moodler committed Apr 26, 2003
1 parent 38e5dbf commit ad08fdc
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 61 deletions.
29 changes: 16 additions & 13 deletions mod/assignment/lib.php
Expand Up @@ -189,20 +189,23 @@ function assignment_print_recent_activity(&$logs, $isteacher=false) {
$content = false;
$assignments = NULL;

foreach ($logs as $log) {
if ($log->module == "assignment" and $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;
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
}
}

Expand Down
71 changes: 37 additions & 34 deletions mod/forum/lib.php
Expand Up @@ -304,46 +304,49 @@ function forum_print_recent_activity(&$logs, $isteacher=false) {

$strftimerecent = get_string("strftimerecent");

foreach ($logs as $log) {
foreach ($logs as $key => $log) {
if ($log->module == "forum") {
//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 ($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>";
} else {
echo "$post->subject";
}
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") {
echo "<b>$post->subject</b>";
} else {
echo "$post->subject";
}
echo "</a>\"</font></p>";
}
}
unset($logs[$key]); // No longer need this record
}
}
return $content;
Expand Down
3 changes: 2 additions & 1 deletion mod/journal/lib.php
Expand Up @@ -125,7 +125,7 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {
$content = false;
$journals = NULL;

foreach ($logs as $log) {
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
Expand All @@ -146,6 +146,7 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {
}
}
}
unset($logs[$key]); // No longer need this record
}
}

Expand Down
29 changes: 16 additions & 13 deletions mod/survey/lib.php
Expand Up @@ -106,20 +106,23 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
$content = false;
$surveys = NULL;

foreach ($logs as $log) {
if ($log->module == "survey" and $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;
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
}
}

Expand Down

0 comments on commit ad08fdc

Please sign in to comment.