Merge pull request #13453 from appwrite/codex/audit-message-team-attribution

perf: cache geo and audit attribution lookups
This commit is contained in:
Luke B. Silver authored and GitHub committed 2026-09-02 17:14:52 +01:00
commit 02ff0a5d43
3 files changed
+53 -2

No files matched your search

+2
View File
@@ -30,6 +30,8 @@ final class Audit extends Base
'$id' => $this->project->getId(),
'$sequence' => $this->project->getSequence(),
'database' => $this->project->getAttribute('database', ''),
'teamId' => $this->project->getAttribute('teamId', ''),
'teamInternalId' => $this->project->getAttribute('teamInternalId', ''),
],
'user' => $this->user->getArrayCopy(),
'impersonatorUser' => $this->impersonatorUser->getArrayCopy(),
+3 -2
View File
@@ -11,7 +11,7 @@ use Utopia\Locale\Locale;
class Geo
{
public const CACHE_SIZE = 10_000;
public const CACHE_VALUE_SIZE = 512;
public const CACHE_VALUE_SIZE = 1024;
public function __construct(
private ?Client $client,
@@ -77,7 +77,8 @@ class Geo
'weatherCode' => $record['weatherCode'] ?? null,
'postalCode' => $record['postalCode'] ?? null,
'city' => $record['city']['en'] ?? null,
'state' => $record['subdivision']['en'] ?? $record['subdivisions'][0]['en'] ?? null,
'state' => $record['subdivision']['en'] ?? $record['subdivisions'][0]['en'] ?? $record['subdivisions'][0]['names']['en'] ?? null,
'subdivisions' => $record['subdivisions'] ?? null,
'autonomousSystemNumber' => $autonomousSystemNumber === null ? null : (string) $autonomousSystemNumber,
'autonomousSystemOrganization' => $record['autonomousSystemOrganization'] ?? null,
'connectionType' => $record['connection'] ?? null,
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Geo;
use Appwrite\Geo\Client;
use Appwrite\Geo\Geo;
use PHPUnit\Framework\TestCase;
use Swoole\Table;
use Utopia\Config\Config;
use Utopia\Locale\Locale;
final class GeoTest extends TestCase
{
public function testCachePreservesPremiumGeoAttributes(): void
{
Config::setParam('locale-eu', []);
Config::setParam('locale-currencies', []);
Locale::setLanguageFromArray('en', []);
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('lookup')
->with('203.0.113.10')
->willReturn([
'countryCode' => 'DE',
'continentCode' => 'EU',
'city' => ['en' => 'Frankfurt'],
'subdivisions' => [
['iso_code' => 'HE', 'names' => ['en' => 'Hesse']],
],
'isp' => 'Example ISP',
]);
$cache = new Table(16);
$cache->column('value', Table::TYPE_STRING, Geo::CACHE_VALUE_SIZE);
$cache->create();
$geo = new Geo($client, new Locale('en'), $cache);
$geo->get('203.0.113.10');
$cached = $geo->get('203.0.113.10');
$this->assertSame('Frankfurt', $cached->getAttribute('city'));
$this->assertSame('Hesse', $cached->getAttribute('subdivisions')[0]['names']['en']);
$this->assertSame('Example ISP', $cached->getAttribute('isp'));
}
}