Some minor performance optimizations

This commit is contained in:
Netkas 2023-06-19 17:38:23 -04:00
parent 40426c293e
commit 6fa23b98d3
No known key found for this signature in database
GPG key ID: 5DAF58535614062B

View file

@ -260,6 +260,8 @@
throw new ClientNotFoundException($client_uuid);
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client name for client %s to %s', $client_uuid, $name));
// Update the record in redis if caching is enabled
if(Configuration::isCacheSystemEnabled() && Configuration::getObjectCacheEnabled('client_objects'))
{
@ -270,25 +272,26 @@
Configuration::getObjectCacheServerFallback('client_objects')
);
if($redis->exists($client_uuid))
if(!$redis->exists($client_uuid))
{
$redis->hSet($client_uuid, 'name', $name);
$redis->hSet($client_uuid, 'updated_timestamp', $update_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'name'));
return;
}
$redis->hSet($client_uuid, 'name', $name);
$redis->hSet($client_uuid, 'updated_timestamp', $update_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'name'));
}
catch(Exception $e)
{
Log::warning(Misc::FEDERATIONLIB, sprintf('Failed to update client object %s in cache: %s', $client_uuid, $e->getMessage()), $e);
}
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client name for client %s to %s', $client_uuid, $name));
}
/**
@ -338,6 +341,8 @@
throw new ClientNotFoundException($client_uuid);
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client description for client %s to %s', $client_uuid, $description));
if(Configuration::isCacheSystemEnabled() && Configuration::getObjectCacheEnabled('client_objects'))
{
try
@ -347,27 +352,26 @@
Configuration::getObjectCacheServerFallback('client_objects')
);
if($redis->exists($client_uuid))
if(!$redis->exists($client_uuid))
{
$redis->hSet($client_uuid, 'description', $description);
$redis->hSet($client_uuid, 'updated_timestamp', $updated_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'description'));
return;
}
$redis->hSet($client_uuid, 'description', $description);
$redis->hSet($client_uuid, 'updated_timestamp', $updated_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'description'));
}
catch(Exception $e)
{
Log::warning(Misc::FEDERATIONLIB, sprintf('Failed to update client object %s in cache: %s', $client_uuid, $e->getMessage()), $e);
}
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client description for client %s to %s', $client_uuid, $description));
}
/**
@ -417,6 +421,8 @@
throw new ClientNotFoundException($client_uuid);
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client permission role for client %s to %s', $client_uuid, $permission_role));
if(Configuration::isCacheSystemEnabled() && Configuration::getObjectCacheEnabled('client_objects'))
{
try
@ -426,26 +432,26 @@
Configuration::getObjectCacheServerFallback('client_objects')
);
if($redis->exists($client_uuid))
if(!$redis->exists($client_uuid))
{
$redis->hSet($client_uuid, 'permission_role', $permission_role);
$redis->hSet($client_uuid, 'updated_timestamp', $updated_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'permission_role'));
return;
}
$redis->hSet($client_uuid, 'permission_role', $permission_role);
$redis->hSet($client_uuid, 'updated_timestamp', $updated_timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($client_uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $client_uuid, 'permission_role'));
}
catch(Exception $e)
{
Log::warning(Misc::FEDERATIONLIB, sprintf('Failed to update client object %s in cache: %s', $client_uuid, $e->getMessage()), $e);
}
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Changed client permission role for client %s to %s', $client_uuid, $permission_role));
}
/**
@ -481,6 +487,8 @@
throw new DatabaseException('Failed to update last seen timestamp: ' . $e->getMessage(), $e);
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Updated last seen timestamp for client %s to %s', $uuid, $timestamp));
if(Configuration::isCacheSystemEnabled() && Configuration::getObjectCacheEnabled('client_objects'))
{
try
@ -490,25 +498,25 @@
Configuration::getObjectCacheServerFallback('client_objects')
);
if($redis->exists($uuid))
if(!$redis->exists($uuid))
{
$redis->hSet($uuid, 'seen_timestamp', $timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $uuid, 'seen_timestamp'));
return;
}
$redis->hSet($uuid, 'seen_timestamp', $timestamp);
if(Configuration::getObjectCacheTTL('client_objects') > 0)
{
$redis->expire($uuid, Configuration::getObjectCacheTTL('client_objects'));
}
Log::debug(Misc::FEDERATIONLIB, sprintf('Updated client object %s <%s> in cache', $uuid, 'seen_timestamp'));
}
catch(Exception $e)
{
Log::warning(Misc::FEDERATIONLIB, sprintf('Failed to update client object %s in cache: %s', $uuid, $e->getMessage()), $e);
}
}
Log::verbose(Misc::FEDERATIONLIB, sprintf('Updated last seen timestamp for client %s to %s', $uuid, $timestamp));
}
/**
@ -604,7 +612,6 @@
throw new DatabaseException('Failed to list clients: ' . $e->getMessage(), $e);
}
unset($client);
return $clients;
}