Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-34867 report_log: Improved download speed and memory usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Bannister committed Nov 28, 2014
1 parent d87bcfb commit b175341
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion admin/tool/log/store/legacy/classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function get_events_select($selectwhere, array $params, $sort, $limitfrom
$records = array();

try {
$records = $DB->get_records_select('log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);
$records = $DB->get_recordset_select('log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);
} catch (\moodle_exception $ex) {
debugging("error converting legacy event data " . $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
}
Expand All @@ -104,6 +104,8 @@ public function get_events_select($selectwhere, array $params, $sort, $limitfrom
$events[$data->id] = \logstore_legacy\event\legacy_logged::restore_legacy($data);
}

$records->close();

return $events;
}

Expand Down
4 changes: 3 additions & 1 deletion admin/tool/log/store/standard/classes/log/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function get_events_select($selectwhere, array $params, $sort, $limitfrom
$sort = self::tweak_sort_by_id($sort);

$events = array();
$records = $DB->get_records_select('logstore_standard_log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);
$records = $DB->get_recordset_select('logstore_standard_log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);

foreach ($records as $data) {
$extra = array('origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid);
Expand All @@ -94,6 +94,8 @@ public function get_events_select($selectwhere, array $params, $sort, $limitfrom
}
}

$records->close();

return $events;
}

Expand Down
38 changes: 26 additions & 12 deletions report/log/classes/table_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,23 @@ public function col_fullnameuser($event) {
if ($event->courseid) {
$params['course'] = $event->courseid;
}
$a->realusername = html_writer::link(new moodle_url("/user/view.php", $params),
$this->userfullnames[$logextra['realuserid']]);
$params['id'] = $event->userid;
$a->asusername = html_writer::link(new moodle_url("/user/view.php", $params),
$this->userfullnames[$event->userid]);
$a->realusername = $this->userfullnames[$logextra['realuserid']];
$a->asusername = $this->userfullnames[$event->userid];
if (empty($this->download)) {
$a->realusername = html_writer::link(new moodle_url('/user/view.php', $params), $a->realusername);
$params['id'] = $event->userid;
$a->asusername = html_writer::link(new moodle_url('/user/view.php', $params), $a->asusername);
}
$username = get_string('eventloggedas', 'report_log', $a);
} else if (!empty($event->userid) && !empty($this->userfullnames[$event->userid])) {
$params = array('id' => $event->userid);
if ($event->courseid) {
$params['course'] = $event->courseid;
}
$username = html_writer::link(new moodle_url("/user/view.php", $params), $this->userfullnames[$event->userid]);
$username = $this->userfullnames[$event->userid];
if (empty($this->download)) {
$username = html_writer::link(new moodle_url('/user/view.php', $params), $username);
}
} else {
$username = '-';
}
Expand All @@ -164,10 +169,14 @@ public function col_relatedfullnameuser($event) {
if ($event->courseid) {
$params['course'] = $event->courseid;
}
return html_writer::link(new moodle_url("/user/view.php", $params), $this->userfullnames[$event->relateduserid]);
$username = $this->userfullnames[$event->relateduserid];
if (empty($this->download)) {
$username = html_writer::link(new moodle_url('/user/view.php', $params), $username);
}
} else {
return '-';
$username = '-';
}
return $username;
}

/**
Expand All @@ -186,7 +195,7 @@ public function col_context($event) {
$context = context::instance_by_id($event->contextid, IGNORE_MISSING);
if ($context) {
$contextname = $context->get_context_name(true);
if ($url = $context->get_url()) {
if ($url = $context->get_url() && empty($this->download)) {
$contextname = html_writer::link($url, $contextname);
}
} else {
Expand Down Expand Up @@ -233,7 +242,8 @@ public function col_eventname($event) {
} else {
$eventname = $event->get_name();
}
if ($url = $event->get_url()) {
// Only encode as an action link if we're not downloading.
if (($url = $event->get_url()) && empty($this->download)) {
$eventname = $this->action_link($url, $eventname, 'action');
}
return $eventname;
Expand Down Expand Up @@ -273,9 +283,13 @@ public function col_origin($event) {
public function col_ip($event) {
// Get extra event data for origin and realuserid.
$logextra = $event->get_logextra();
$ip = $logextra['ip'];

$url = new moodle_url("/iplookup/index.php?ip={$logextra['ip']}&user=$event->userid");
return $this->action_link($url, $logextra['ip'], 'ip');
if (empty($this->download)) {
$url = new moodle_url("/iplookup/index.php?ip={$ip}&user={$event->userid}");
$ip = $this->action_link($url, $ip, 'ip');
}
return $ip;
}

/**
Expand Down

0 comments on commit b175341

Please sign in to comment.