Merge branch 'MDL-30643_master-log-speed' of git://github.com/tbannister/moodle

Conflicts:
	lib/tests/statslib_test.php
This commit is contained in:
Aparup Banerjee 2012-11-15 11:15:00 +08:00
commit 244e907235
3 changed files with 29 additions and 27 deletions

View File

@ -2931,4 +2931,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -251,7 +251,7 @@ function stats_cron_daily($maxdays=1) {
userid, COUNT(id) AS statsreads
FROM {temp_log1} l
WHERE action = 'login'
GROUP BY timeend, courseid, userid
GROUP BY userid
HAVING COUNT(id) > 0";
if ($logspresent && !stats_run_query($sql)) {
@ -429,7 +429,7 @@ function stats_cron_daily($maxdays=1) {
SUM(CASE WHEN action $viewactionssql THEN 1 ELSE 0 END) AS statsreads,
SUM(CASE WHEN action $postactionssql THEN 1 ELSE 0 END) AS statswrites
FROM {temp_log1} l
GROUP BY userid, courseid";
GROUP BY userid, course";
if ($logspresent && !stats_run_query($sql, array_merge($params1, $params2))) {
$failed = true;
@ -446,7 +446,7 @@ function stats_cron_daily($maxdays=1) {
SUM(CASE WHEN l.action $postactionssql THEN 1 ELSE 0 END) AS stat2
FROM {course} c, {temp_log1} l
WHERE l.course = c.id
GROUP BY courseid";
GROUP BY c.id";
if ($logspresent && !stats_run_query($sql, array_merge($params1, $params2))) {
$failed = true;
@ -477,7 +477,7 @@ function stats_cron_daily($maxdays=1) {
AND sud.stattype='activity'
) inline_view
GROUP BY timeend, courseid, roleid
GROUP BY courseid, roleid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
if ($logspresent && !stats_run_query($sql, array('courselevel'=>CONTEXT_COURSE))) {
@ -508,7 +508,7 @@ function stats_cron_daily($maxdays=1) {
))
) inline_view
GROUP BY timeend, courseid, roleid
GROUP BY courseid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
if ($logspresent && !stats_run_query($sql, array())) {
@ -541,7 +541,7 @@ function stats_cron_daily($maxdays=1) {
AND sud.stattype='activity'
) inline_view
GROUP BY timeend, courseid, roleid
GROUP BY courseid, roleid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
if ($logspresent && !stats_run_query($sql, array('fpcontext'=>$fpcontext->id))) {
@ -573,7 +573,7 @@ function stats_cron_daily($maxdays=1) {
AND ra.contextid = :fpcontext)
) inline_view
GROUP BY timeend, courseid, roleid
GROUP BY timeend, courseid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
if ($logspresent && !stats_run_query($sql, array('fpcontext'=>$fpcontext->id, 'siteid'=>SITEID, 'nextm'=>$nextmidnight))) {
@ -585,20 +585,19 @@ function stats_cron_daily($maxdays=1) {
// How many view actions for guests or not-logged-in on frontpage
$sql = "INSERT INTO {temp_stats_daily} (stattype, timeend, courseid, roleid, stat1, stat2)
SELECT 'activity', $nextmidnight AS timeend, ".SITEID." AS courseid, $guestrole AS roleid,
SUM(statsreads), SUM(statswrites)
SELECT stattype, timeend, courseid, $guestrole AS roleid,
SUM(statsreads) AS stat1, SUM(statswrites) AS stat2
FROM (
SELECT sud.statsreads, sud.statswrites
SELECT sud.stattype, sud.timeend, sud.courseid,
sud.statsreads, sud.statswrites
FROM {temp_stats_user_daily} sud
WHERE (sud.userid = $guest OR sud.userid = 0)
AND sud.timeend = $nextmidnight
AND sud.courseid = ".SITEID."
AND sud.stattype='activity'
) inline_view
GROUP BY timeend, courseid, roleid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
) inline_view
GROUP BY stattype, timeend, courseid
HAVING SUM(statsreads) > 0 OR SUM(statswrites) > 0";
if ($logspresent && !stats_run_query($sql)) {
$failed = true;
@ -1549,7 +1548,6 @@ function stats_temp_table_create() {
stats_temp_table_drop();
$xmlfile = $CFG->dirroot . '/lib/db/install.xml';
$tempfile = $CFG->dirroot . '/lib/db/temp_stats_log_template.xml';
$tables = array();
// Allows for the additional xml files to be used (if necessary)
@ -1580,7 +1578,7 @@ function stats_temp_table_create() {
if (is_null($table)) {
throw new ddl_exception('ddlunknowntable', null, 'The table '. $name .' is not defined in the file '. $xmlfile);
}
$table->setNext(null);
$table->setNext(null);
$table->setPrevious(null);
foreach ($names as $name) {

View File

@ -246,7 +246,7 @@ class statslib_daily_testcase extends advanced_testcase {
*
* @param array $stats An array of arrays of arrays of both types of stats
*/
protected function verify_stats($expected) {
protected function verify_stats($expected, $output = '') {
global $DB;
// Note: We can not use $this->assertDataSetEqual($expected, $actual) because there's no
@ -257,8 +257,13 @@ class statslib_daily_testcase extends advanced_testcase {
$rows = $table->getRowCount();
$this->assertEquals($rows, sizeof($records),
'Incorrect number of results returned for '. $type);
$message = 'Incorrect number of results returned for '. $type;
if ($output != '') {
$message .= "\nCron output:\n$output";
}
$this->assertEquals($rows, sizeof($records), $message);
for ($i = 0; $i < $rows; $i++) {
$row = $table->getRow($i);
@ -275,6 +280,7 @@ class statslib_daily_testcase extends advanced_testcase {
break;
}
}
$this->assertGreaterThan(0, $found, 'Expected log '. var_export($row, true)
." was not found in $type ". var_export($records, true));
unset($records[$found]);
@ -569,16 +575,15 @@ class statslib_daily_testcase extends advanced_testcase {
public function test_statslib_cron_daily($logs, $stats) {
global $CFG, $DB;
$CFG->debug = DEBUG_NONE;
$this->prepare_db($logs, array('log'));
// Stats cron daily uses mtrace, turn on buffering to silence output.
ob_start();
stats_cron_daily(1);
$output = ob_get_contents();
ob_end_clean();
$this->verify_stats($stats);
$this->verify_stats($stats, $output);
}
/**
@ -599,15 +604,14 @@ class statslib_daily_testcase extends advanced_testcase {
$dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test10.xml");
$CFG->debug = DEBUG_NONE;
$this->prepare_db($dataset[0], array('log'));
// Stats cron daily uses mtrace, turn on buffering to silence output.
ob_start();
stats_cron_daily($maxdays=1);
$output = ob_get_contents();
ob_end_clean();
$this->verify_stats($dataset[1]);
$this->verify_stats($dataset[1], $output);
}
}