Commit 02a60fb4 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Problem with oversized sql IN() clause (Bug #1308792)



Currently institution data daily cronjob fails if the number of items
wanted to be prepared for the IN() clause exceeds 46,000. This causes
adodb to hit memory limit and fail out.

Have taken the three sql commands from various places that make up the
call and made them nested to avoid overly long prepared statement.

Change-Id: I5e38c01194f7b2c3f3899c1573a69411ac273c18
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 566a610d
......@@ -1462,13 +1462,27 @@ function institution_view_type_graph(&$institutiondata) {
if ($institutiondata['views'] == 0) {
return;
}
$institution = $institutiondata['name'];
$values = array();
// Draw a pie graph of views broken down by view type.
$values[] = 'dashboard';
if ($institution == 'mahara') {
$where = 'institution IS NULL';
}
else {
$where = 'institution = ?';
$values[] = $institution;
}
$values[] = $institution;
$viewtypes = get_records_sql_array('
SELECT type, COUNT(id) AS views
FROM {view} WHERE type != ?
AND id IN (' . join(',', array_fill(0, $institutiondata['views'], '?')) . ')
GROUP BY type',
array_merge(array('dashboard'), $institutiondata['viewids'])
AND id IN (
SELECT id FROM {view} WHERE owner IS NOT NULL AND owner IN (
SELECT u.id FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr
WHERE ' . $where . ' AND u.id != 0 AND deleted = 0
) UNION SELECT id FROM {view} WHERE institution IS NOT NULL AND institution = ?
) GROUP BY type', $values
);
if (count($viewtypes) > 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment