Skip to content
Snippets Groups Projects
Commit 8da7257c authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

optimize cache and notification handling for RolePersistence, fixes #644

parent b8c3503a
No related branches found
No related tags found
No related merge requests found
...@@ -63,10 +63,6 @@ class RolePersistence ...@@ -63,10 +63,6 @@ class RolePersistence
*/ */
public static function saveRole($role) public static function saveRole($role)
{ {
// sweep roles cache, see #getAllRoles
self::expireRolesCache();
// role is not in database
$query = "INSERT INTO `roles` (`roleid`, `rolename`, `system`) $query = "INSERT INTO `roles` (`roleid`, `rolename`, `system`)
VALUES (?, ?, 'n') VALUES (?, ?, 'n')
ON DUPLICATE KEY UPDATE `rolename` = VALUES(`rolename`)"; ON DUPLICATE KEY UPDATE `rolename` = VALUES(`rolename`)";
...@@ -82,6 +78,9 @@ class RolePersistence ...@@ -82,6 +78,9 @@ class RolePersistence
$event = 'RoleDidUpdate'; $event = 'RoleDidUpdate';
} }
// sweep roles cache, see #getAllRoles
self::expireRolesCache();
NotificationCenter::postNotification( NotificationCenter::postNotification(
$event, $event,
$role->getRoleid(), $role->getRoleid(),
...@@ -101,18 +100,11 @@ class RolePersistence ...@@ -101,18 +100,11 @@ class RolePersistence
$id = $role->getRoleid(); $id = $role->getRoleid();
$name = $role->getRolename(); $name = $role->getRolename();
// sweep roles cache
self::expireRolesCache();
$query = "SELECT `pluginid` FROM `roles_plugins` WHERE `roleid` = ?"; $query = "SELECT `pluginid` FROM `roles_plugins` WHERE `roleid` = ?";
$statement = DBManager::get()->prepare($query); $statement = DBManager::get()->prepare($query);
$statement->execute([$id]); $statement->execute([$id]);
$statement->setFetchMode(PDO::FETCH_COLUMN, 0); $statement->setFetchMode(PDO::FETCH_COLUMN, 0);
foreach ($statement as $plugin_id) {
unset(self::getPluginRolesCache()[$plugin_id]);
}
DBManager::get()->execute( DBManager::get()->execute(
"DELETE `roles`, `roles_user`, `roles_plugins`, `roles_studipperms` "DELETE `roles`, `roles_user`, `roles_plugins`, `roles_studipperms`
FROM `roles` FROM `roles`
...@@ -123,6 +115,13 @@ class RolePersistence ...@@ -123,6 +115,13 @@ class RolePersistence
[$id] [$id]
); );
// sweep roles cache
self::expireRolesCache();
foreach ($statement as $plugin_id) {
unset(self::getPluginRolesCache()[$plugin_id]);
}
NotificationCenter::postNotification('RoleDidDelete', $id, $name); NotificationCenter::postNotification('RoleDidDelete', $id, $name);
} }
...@@ -322,8 +321,6 @@ class RolePersistence ...@@ -322,8 +321,6 @@ class RolePersistence
{ {
$plugin_id = (int) $plugin_id; $plugin_id = (int) $plugin_id;
unset(self::getPluginRolesCache()[$plugin_id]);
$query = "REPLACE INTO `roles_plugins` (`roleid`, `pluginid`) $query = "REPLACE INTO `roles_plugins` (`roleid`, `pluginid`)
VALUES (:role_id, :plugin_id)"; VALUES (:role_id, :plugin_id)";
$statement = DBManager::get()->prepare($query); $statement = DBManager::get()->prepare($query);
...@@ -332,13 +329,16 @@ class RolePersistence ...@@ -332,13 +329,16 @@ class RolePersistence
foreach ($role_ids as $role_id) { foreach ($role_ids as $role_id) {
$statement->bindValue(':role_id', $role_id); $statement->bindValue(':role_id', $role_id);
$statement->execute(); $statement->execute();
}
unset(self::getPluginRolesCache()[$plugin_id]);
foreach ($role_ids as $role_id) {
NotificationCenter::postNotification( NotificationCenter::postNotification(
'PluginRoleAssignmentDidCreate', 'PluginRoleAssignmentDidCreate',
$role_id, $role_id,
$plugin_id $plugin_id
); );
} }
} }
...@@ -352,8 +352,6 @@ class RolePersistence ...@@ -352,8 +352,6 @@ class RolePersistence
{ {
$plugin_id = (int) $plugin_id; $plugin_id = (int) $plugin_id;
unset(self::getPluginRolesCache()[$plugin_id]);
$query = "DELETE FROM `roles_plugins` $query = "DELETE FROM `roles_plugins`
WHERE `pluginid` = :plugin_id WHERE `pluginid` = :plugin_id
AND `roleid` = :role_id"; AND `roleid` = :role_id";
...@@ -363,13 +361,16 @@ class RolePersistence ...@@ -363,13 +361,16 @@ class RolePersistence
foreach ($role_ids as $role_id) { foreach ($role_ids as $role_id) {
$statement->bindValue(':role_id', $role_id); $statement->bindValue(':role_id', $role_id);
$statement->execute(); $statement->execute();
}
unset(self::getPluginRolesCache()[$plugin_id]);
foreach ($role_ids as $role_id) {
NotificationCenter::postNotification( NotificationCenter::postNotification(
'PluginRoleAssignmentDidDelete', 'PluginRoleAssignmentDidDelete',
$role_id, $role_id,
$plugin_id $plugin_id
); );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment