Reduce (only a tad but still) the potential number of queries done when updating permissions

git-svn-id: file:///svn/phpbb/trunk@3878 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-04-17 22:59:51 +00:00
parent e93d9d23f2
commit a79524cb33

View file

@ -1663,34 +1663,76 @@ if (class_exists(auth))
switch ($setting) switch ($setting)
{ {
case ACL_UNSET: case ACL_UNSET:
$sql_ary[] = "DELETE FROM $table if (isset($cur_auth[$forum][$auth_option_id]))
{
$sql_ary['delete'][] = "DELETE FROM $table
WHERE forum_id = $forum WHERE forum_id = $forum
AND auth_option_id = $auth_option_id AND auth_option_id = $auth_option_id
AND $id_field = $ug_id"; AND $id_field = $ug_id";
}
break; break;
default: default:
if (isset($cur_auth[$forum][$auth_option_id]) && $cur_auth[$forum][$auth_option_id] != $setting) if (!isset($cur_auth[$forum][$auth_option_id]))
{ {
$sql_ary[] = "UPDATE " . $table . " $sql_ary['insert'][] = "$ug_id, $forum, $auth_option_id, $setting";
}
else if ($cur_auth[$forum][$auth_option_id] != $setting)
{
$sql_ary['update'][] = "UPDATE " . $table . "
SET auth_setting = $setting SET auth_setting = $setting
WHERE $id_field = $ug_id WHERE $id_field = $ug_id
AND forum_id = $forum AND forum_id = $forum
AND auth_option_id = $auth_option_id"; AND auth_option_id = $auth_option_id";
} }
else if (!isset($cur_auth[$forum][$auth_option_id]))
{
$sql_ary[] = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting)
VALUES ($ug_id, $forum, $auth_option_id, $setting)";
}
} }
} }
} }
unset($cur_auth); unset($cur_auth);
foreach ($sql_ary as $sql) $sql = '';
foreach ($sql_ary as $sql_type => $sql_subary)
{
switch ($sql_type)
{
case 'insert':
switch (SQL_LAYER)
{
case 'mysql':
case 'mysql4':
$sql = implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary));
break;
case 'mssql':
$sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
break;
default:
foreach ($sql_subary as $sql)
{
$sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) VALUES ($sql)";
$db->sql_query($sql);
$sql = '';
}
}
if ($sql != '')
{
$sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) VALUES $sql";
$db->sql_query($sql);
}
break;
case 'update':
case 'delete':
foreach ($sql_subary as $sql)
{ {
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
$sql = '';
}
break;
}
unset($sql_ary[$sql_type]);
} }
unset($sql_ary); unset($sql_ary);