Some minor performance optimizations
This commit is contained in:
parent
40426c293e
commit
6fa23b98d3
1 changed files with 55 additions and 48 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue