jenkins-bot has submitted this change and it was merged.
Change subject: Added OpenStackNovaRole::getRoleNameForId
......................................................................
Added OpenStackNovaRole::getRoleNameForId
This new function caches the global role list, which means
one less keystone call each time we initialize a role.
Change-Id: I595ae53b419656818f50373d2fac251a5af8a261
---
M nova/OpenStackNovaRole.php
1 file changed, 22 insertions(+), 10 deletions(-)
Approvals:
Andrew Bogott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/nova/OpenStackNovaRole.php b/nova/OpenStackNovaRole.php
index 44f3aab..292727b 100644
--- a/nova/OpenStackNovaRole.php
+++ b/nova/OpenStackNovaRole.php
@@ -24,16 +24,7 @@
$this->project = $project;
OpenStackNovaLdapConnection::connect();
- # Get the name by searching the global role list
- $controller = OpenstackNovaProject::getController();
- $globalrolelist = $controller->getKeystoneRoles();
- $this->rolename = 'unknown role';
- foreach ( $globalrolelist as $id => $name ) {
- if ( $id == $this->roleid ) {
- $this->rolename = $name;
- break;
- }
- }
+ $this->rolename = OpenStackNovaRole::getRoleNameForId(
$this->roleid );
}
/**
@@ -197,4 +188,25 @@
}
return null;
}
+
+ /**
+ * @static
+ * @param $roleid
+ * @return role name
+ */
+ static function getRoleNameForId( $roleid ) {
+ global $wgMemc;
+
+ $key = wfMemcKey( 'openstackmanager', 'globalrolelist' );
+ $globalrolelist = $wgMemc->get( $key );
+ if ( ! is_array( $globalrolelist ) ) {
+ $controller = OpenstackNovaProject::getController();
+ $globalrolelist = $controller->getKeystoneRoles();
+
+ # Roles basically never change, so this can be a
long-lived cache
+ $wgMemc->set( $key, $globalrolelist );
+ }
+
+ return isset( $globalrolelist[$roleid] ) ?
$globalrolelist[$roleid] : "unknown role";
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/270500
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I595ae53b419656818f50373d2fac251a5af8a261
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: wmf/1.27.0-wmf.13
Gerrit-Owner: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits