]> git.mjollnir.org Git - moodle.git/commitdiff
Performance improvements
authormoodler <moodler>
Sat, 26 Apr 2003 12:59:41 +0000 (12:59 +0000)
committermoodler <moodler>
Sat, 26 Apr 2003 12:59:41 +0000 (12:59 +0000)
  - better checking of data before processing
  - used logs are removed to avoid re-processing by other modules

mod/assignment/lib.php
mod/forum/lib.php
mod/journal/lib.php
mod/survey/lib.php

index b5e68c867367271d7f10ef2d558c7164e4bf5f32..3f3031d7e65dc1d26dd09cb563a55fe1ede2d909 100644 (file)
@@ -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
         }
     }
 
index f04de9bd03b81e43943f1723b0ed03ae72439766..72ada4c436105cb7df7b578b5a3db2b7f2c45c2f 100644 (file)
@@ -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;
index 0be5d42d71076a58ddaa26ca61e1327330766276..f932e27a682b849aa266d6e38d0d1d8663ae6041 100644 (file)
@@ -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
@@ -146,6 +146,7 @@ function journal_print_recent_activity(&$logs, $isteacher=false) {
                     }
                 }
             }
+            unset($logs[$key]);  // No longer need this record
         }
     }
 
index 83b865288cd67e306d7f233c3f8e25daae4b6ecc..406d51d2e284f8ab8829b765fea045cf501f8ced 100644 (file)
@@ -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
         }
     }