MDL-48856 dmllib: Adjust performance improvements.

This commit is contained in:
Russell Smith 2016-07-01 09:12:41 +10:00
parent 73d37b20ed
commit e868574f02

View File

@ -586,6 +586,8 @@ class pgsql_native_moodle_database extends moodle_database {
* @return mixed the normalised value
*/
protected function normalise_value($column, $value) {
$this->detect_objects($value);
if (is_bool($value)) { // Always, convert boolean to int
$value = (int)$value;
@ -600,8 +602,6 @@ class pgsql_native_moodle_database extends moodle_database {
if ($column->meta_type === 'I' or $column->meta_type === 'F' or $column->meta_type === 'N') {
$value = 0; // prevent '' problems in numeric fields
}
} else if (is_object($value)) {
$this->detect_objects($value);
}
return $value;
}
@ -678,11 +678,7 @@ class pgsql_native_moodle_database extends moodle_database {
}
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
if (empty($params)) {
$result = pg_query($this->pgsql, $sql);
} else {
$result = pg_query_params($this->pgsql, $sql, $params);
}
$result = pg_query_params($this->pgsql, $sql, $params);
$this->query_end($result);
pg_free_result($result);
@ -710,19 +706,11 @@ class pgsql_native_moodle_database extends moodle_database {
list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum);
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
} else if (PHP_INT_MAX - $limitnum < $limitfrom) {
// this is a workaround for weird max int problem
$limitnum = "ALL";
}
if ($limitnum != 'ALL') {
$sql .= " LIMIT $limitnum";
}
if (!empty($limitfrom)) {
$sql .= " OFFSET $limitfrom";
}
if ($limitnum) {
$sql .= " LIMIT $limitnum";
}
if ($limitfrom) {
$sql .= " OFFSET $limitfrom";
}
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
@ -757,19 +745,11 @@ class pgsql_native_moodle_database extends moodle_database {
list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum);
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
} else if (PHP_INT_MAX - $limitnum < $limitfrom) {
// this is a workaround for weird max int problem
$limitnum = "ALL";
}
if ($limitnum != 'ALL') {
$sql .= " LIMIT $limitnum";
}
if (!empty($limitfrom)) {
$sql .= " OFFSET $limitfrom";
}
if ($limitnum) {
$sql .= " LIMIT $limitnum";
}
if ($limitfrom) {
$sql .= " OFFSET $limitfrom";
}
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
@ -787,9 +767,12 @@ class pgsql_native_moodle_database extends moodle_database {
}
}
$rows = pg_fetch_all($result);
pg_free_result($result);
$return = array();
if ($result) {
while ($row = pg_fetch_object($result)) {
if ($rows) {
foreach ($rows as $row) {
$id = reset($row);
if ($blobs) {
foreach ($blobs as $blob) {
@ -797,14 +780,13 @@ class pgsql_native_moodle_database extends moodle_database {
}
}
if (isset($return[$id])) {
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$id' found in column '".key($row)."'.", DEBUG_DEVELOPER);
$colname = key($row);
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$id' found in column '$colname'.", DEBUG_DEVELOPER);
}
$return[$id] = $row;
$return[$id] = (object)$row;
}
}
pg_free_result($result);
return $return;
}