Skip to content

Commit

Permalink
Cache details and include migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez committed Jul 25, 2022
1 parent 9f7a03a commit b86e444
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
37 changes: 37 additions & 0 deletions appinfo/Migrations/Version20220725070804.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace OCA\User_LDAP\Migrations;

use OCP\Migration\ISimpleMigration;
use OCP\Migration\IOutput;
use OCP\IConfig;
use OCA\User_LDAP\Helper;

class Version20220725070804 implements ISimpleMigration {
/** @var IConfig */
private $config;
/** @var $helper */
private $helper;

/**
* @param IConfig $config
*/
public function __construct(IConfig $config, Helper $helper) {
$this->config = $config;
$this->helper = $helper;
}
/**
* @param IOutput $out
*/
public function run(IOutput $out) {
$prefixes = $this->helper->getServerConfigurationPrefixes();
foreach ($prefixes as $prefix) {
$groupnameValue = $this->config->getAppValue('user_ldap', "{$prefix}ldap_expert_groupname_attr", null);
if ($groupnameValue === null) {
$groupDisplaynameValue = $this->config->getAppValue('user_ldap', "{$prefix}ldap_group_display_name", null);
if ($groupDisplaynameValue !== null) {
$this->config->setAppValue('user_ldap', "{$prefix}ldap_expert_groupname_attr", $groupDisplaynameValue);
}
}
}
}
}
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ More information is available in the [LDAP User and Group Backend documentation]
</description>
<licence>AGPL</licence>
<author>Jörn Friedrich Dreyer, Tom Needham, Juan Pablo Villafañez Ramos, Dominik Schmidt and Arthur Schiwon</author>
<version>0.16.0</version>
<version>0.17.0</version>
<types>
<authentication/>
</types>
Expand Down
11 changes: 10 additions & 1 deletion lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,12 @@ public function groupExists($gid) {
}

public function getGroupDetails($gid) {
$cacheKey = "groupDetails-$gid";
$details = $this->access->getConnection()->getFromCache($cacheKey);
if ($details !== null) {
return $details;
}

$dn = $this->access->groupname2dn($gid);
if ($dn === false) {
// FIXME: It seems local groups also end up going through here...
Expand All @@ -1010,10 +1016,13 @@ public function getGroupDetails($gid) {

$attr = $this->access->getConnection()->ldapGroupDisplayName;
$displayname = $this->access->readAttribute($dn, $attr);
return [

$details = [
'gid' => $gid,
'displayName' => $displayname[0],
];
$this->access->getConnection()->writeToCache($cacheKey, $details);
return $details;
}

/**
Expand Down

0 comments on commit b86e444

Please sign in to comment.