Skip to content

Commit

Permalink
improving performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Wolniewicz committed Jul 2, 2024
1 parent 813365a commit 5fd9caf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
11 changes: 9 additions & 2 deletions core/Federation.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Federation extends EntityWithDBProperties
* @var string
*/
public $tld;


private $idpArray = [];
/**
* retrieve the statistics from the database in an internal array representation
*
Expand Down Expand Up @@ -231,6 +232,7 @@ public function __construct($fedname)
} else {
throw new Exception("This database type is never an array!");
}
$this->loggerInstance->debug(4, $fedname, "Creating federation:", " \n");
// fetch attributes from DB; populates $this->attributes array
$this->attributes = $this->retrieveOptionsFromDatabase("SELECT DISTINCT option_name, option_lang, option_value, row_id
FROM $this->entityOptionTable
Expand Down Expand Up @@ -532,7 +534,12 @@ public function listIdentityProviders($activeOnly = 0)
$returnarray = [];
// SELECT -> resource, not boolean
while ($idpQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $allIDPs)) {
$idp = new IdP($idpQuery->inst_id);
if (isset($this->idpArray[$idpQuery->inst_id])) {
$idp = $this->idpArray[$idpQuery->inst_id];
} else {
$idp = new IdP($idpQuery->inst_id);
$this->idpArray[$idpQuery->inst_id] = $idp;
}
if (!isset($idpQuery->realms)) {
$idpQuery->realms = '';
}
Expand Down
25 changes: 11 additions & 14 deletions core/IdP.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(int $instId)

$this->identifier = $instId;

$idp = $this->databaseHandle->exec("SELECT inst_id, country,external_db_syncstate FROM institution WHERE inst_id = $this->identifier");
$idp = $this->databaseHandle->exec("SELECT inst_id, country,external_db_syncstate, type FROM institution WHERE inst_id = $this->identifier");
// SELECT -> returns resource, not boolean
if (!$instQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $idp)) {
throw new Exception("IdP $this->identifier not found in database!");
Expand All @@ -113,7 +113,7 @@ public function __construct(int $instId)
"flag" => NULL];

$this->name = $this->languageInstance->getLocalisedValue($this->getAttributes('general:instname'));
$eligibility = $this->eligibility();
$eligibility = $this->eligibility($instQuery->type);
if (in_array(IdP::ELIGIBILITY_IDP, $eligibility) && in_array(IdP::ELIGIBILITY_SP, $eligibility)) {
$eligType = IdP::TYPE_IDPSP . "";
$this->type = $eligType;
Expand All @@ -123,7 +123,7 @@ public function __construct(int $instId)
$eligType = IdP::TYPE_SP . "";
}
$this->type = $eligType;
$this->loggerInstance->debug(4, "--- END Constructing new IdP object ... ---\n");
$this->loggerInstance->debug(4, "--- END Constructing new IdP object $instId ... ---\n");
}

/**
Expand Down Expand Up @@ -301,18 +301,15 @@ public function deploymentCount()
*
* @return array list of eligibilities
*/
public function eligibility()
public function eligibility($type)
{
$eligibilites = $this->databaseHandle->exec("SELECT type FROM institution WHERE inst_id = $this->identifier");
while ($iterator = mysqli_fetch_object(/** @scrutinizer ignore-type */ $eligibilites)) {
switch ($iterator->type) {
case "IdP":
return [IdP::ELIGIBILITY_IDP];
case "SP":
return [IdP::ELIGIBILITY_SP];
default:
return [IdP::ELIGIBILITY_IDP, IdP::ELIGIBILITY_SP];
}
switch ($type) {
case "IdP":
return [IdP::ELIGIBILITY_IDP];
case "SP":
return [IdP::ELIGIBILITY_SP];
default:
return [IdP::ELIGIBILITY_IDP, IdP::ELIGIBILITY_SP];
}
}

Expand Down
9 changes: 8 additions & 1 deletion schema/2_1_1-2_1_2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@


UPDATE profile_option_dict SET flag='SPECIFIC' WHERE name = 'device-specific:geteduroam';
UPDATE profile_option_dict SET flag='SPECIFIC' WHERE name = 'device-specific:geantlink';
UPDATE profile_option_dict SET flag='SPECIFIC' WHERE name = 'device-specific:geantlink';
ALTER TABLE profile_option ADD KEY profile_id (profile_id);
ALTER TABLE profile ADD KEY showtime (showtime);
ALTER TABLE profile ADD KEY sufficient_config (sufficient_config);
ALTER TABLE profile ADD KEY openroaming (openroaming);
ALTER TABLE institution ADD KEY country (country);
ALTER TABLE institution ADD KEY external_db_id (external_db_id);
ALTER TABLE institution ADD KEY external_db_syncstate (external_db_syncstate);
12 changes: 7 additions & 5 deletions web/admin/overview_federation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

//$OpenRoamingSymbol = "<img src='../resources/images/icons/or.svg' alt='OpenRoaming' title='OpenRoaming' class='cat-icon'>";
$OpenRoamingSymbol = "OR";
$fedArray = [];
$stausIcons = [
\core\IdP::PROFILES_SHOWTIME => ['img' => 'Tabler/checks-green.svg', 'text' => _("At least one profile is fully configured and visible in the user interface")],
\core\IdP::PROFILES_CONFIGURED => ['img' => 'Tabler/check-green.svg', 'text' => _("At least one profile is fully configured but none are set as production-ready therefore the institution is not visible in the user interface")],
Expand Down Expand Up @@ -128,9 +129,12 @@

<?php
}

foreach ($feds as $onefed) {
$thefed = new \core\Federation(strtoupper($onefed['value']));
$fedId = strtoupper($onefed['value']);
$fedArray[$fedId] = new \core\Federation($fedId);
}

foreach ($fedArray as $fedId => $thefed) {
?>

<div class='infobox'><h2>
Expand Down Expand Up @@ -314,9 +318,7 @@
</tr>
<?php
$userIdps = $user->listOwnerships();
foreach ($feds as $onefed) {
$fedId = strtoupper($onefed['value']);
$thefed = new \core\Federation($fedId);
foreach ($fedArray as $fedId => $thefed) {
/// nomenclature for 'federation', federation name, nomenclature for 'inst'
echo "<tr><td colspan='9'><strong>".sprintf(_("The following %s are in your %s %s:"), $uiElements->nomenclatureParticipant, $uiElements->nomenclatureFed, '<span style="color:green">'.$thefed->name.'</span>')."</strong></td></tr>";
echo "<tbody class='fedlist'>";
Expand Down

0 comments on commit 5fd9caf

Please sign in to comment.