Permalink
Browse files

Alternate method of calculating usercourse logs .... is it faster?

  • Loading branch information...
1 parent 5be2f47 commit e45e8d26da63c137a0adaaa7d4bfef32d11c2089 martin committed Sep 2, 2002
Showing with 15 additions and 8 deletions.
  1. +15 −8 course/loggraph.php
View
@@ -38,21 +38,28 @@
if ($timenow - $course->startdate > $COURSE_MAX_LOG_DISPLAY) {
$course->startdate = $timenow - $COURSE_MAX_LOG_DISPLAY;
}
- $timestart = usergetmidnight($course->startdate);
+ $timestart = $coursestart = usergetmidnight($course->startdate);
+
$i = 0;
while ($timestart < $timenow) {
- $timefinish = $timestart + (3600 * 24);
- if (! $logcount = get_record_sql("SELECT COUNT(*) as count FROM log
- WHERE user = '$user->id' AND course = '$course->id'
- AND `time` > '$timestart' AND `time` < '$timefinish'")) {
- $logs[$i] = 0;
- }
- $logs[$i] = $logcount->count;
+ $timefinish = $timestart + 86400;
$days[$i] = userdate($timestart, "%a %e %b");
+ $logs[$i] = 0;
$i++;
$timestart = $timefinish;
}
+ if ($rawlogs = get_records_sql("SELECT floor((`time` - $coursestart)/86400) as day,
+ count(*) as num FROM log
+ WHERE user = '$user->id'
+ AND course = '$course->id'
+ AND `time` > '$coursestart'
+ GROUP BY day ")) {
+ foreach ($rawlogs as $rawlog) {
+ $logs[$rawlog->day] = $rawlog->num;
+ }
+ }
+
$maxlogs = max($logs);

0 comments on commit e45e8d2

Please sign in to comment.