Merge pull request #12645 from appwrite/feat/sort-by-accessed-at

feat: allow sorting by accessedAt for users and projects
This commit is contained in:
Harsh Mahajan authored and GitHub committed 2026-07-02 11:35:15 +05:30
commit 133fb130db
7 files changed
+126 -1

No files matched your search

+7
View File
@@ -415,6 +415,13 @@ $platformCollections = [
'lengths' => [],
'orders' => [],
],
[
'$id' => ID::custom('_key_accessedAt'),
'type' => Database::INDEX_KEY,
'attributes' => ['accessedAt'],
'lengths' => [],
'orders' => [],
],
[
'$id' => ID::custom('_key_teamInternalId'),
'type' => Database::INDEX_KEY,
+1
View File
@@ -98,6 +98,7 @@ abstract class Migration
'1.9.3' => 'V24',
'1.9.4' => 'V24',
'1.9.5' => 'V24',
'2.0.0' => 'V25',
];
/**
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace Appwrite\Migration\Version;
use Appwrite\Migration\Migration;
use Exception;
use Throwable;
use Utopia\Console;
use Utopia\Database\Database;
class V25 extends Migration
{
/**
* @throws Throwable
*/
public function execute(): void
{
Console::info('Migrating collections');
$this->migrateCollections();
}
/**
* Migrate Collections.
*
* @return void
* @throws Exception|Throwable
*/
private function migrateCollections(): void
{
$projectInternalId = $this->project->getSequence();
if (empty($projectInternalId)) {
throw new Exception('Project ID is null');
}
$collectionType = match ($projectInternalId) {
'console' => 'console',
default => 'projects',
};
$collections = $this->collections[$collectionType];
foreach ($collections as $collection) {
$id = $collection['$id'];
if (empty($id)) {
continue;
}
Console::log("Migrating collection \"{$id}\"");
$this->dbForProject->purgeCachedCollection($id);
$this->dbForProject->purgeCachedDocument(Database::METADATA, $id);
switch ($id) {
case 'projects':
if ($collectionType === 'console') {
try {
$this->createIndexFromCollection($this->dbForProject, $id, '_key_accessedAt');
} catch (Throwable $th) {
Console::warning("Failed to create index \"_key_accessedAt\" from {$id}: {$th->getMessage()}");
}
}
$this->dbForProject->purgeCachedCollection($id);
break;
}
}
}
}
@@ -8,7 +8,8 @@ class Projects extends Base
'name',
'teamId',
'labels',
'search'
'search',
'accessedAt',
];
/**
@@ -15,6 +15,7 @@ class Users extends Base
'phoneVerification',
'labels',
'impersonator',
'accessedAt',
];
/**
@@ -1531,6 +1531,28 @@ final class ProjectsConsoleClientTest extends Scope
], $this->getHeaders()));
$this->assertEquals(404, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::orderDesc('accessedAt')->toString()
]
]);
$this->assertEquals(200, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::orderAsc('accessedAt')->toString()
]
]);
$this->assertEquals(200, $response['headers']['status-code']);
}
public function testGetProjectUsage(): void
+24
View File
@@ -1156,6 +1156,30 @@ trait UsersBase
$this->assertEquals($user['body']['code'], 404);
$this->assertEquals($user['body']['message'], 'User with the requested ID could not be found.');
$this->assertEquals($user['body']['type'], 'user_not_found');
$response = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::orderDesc('accessedAt')->toString()
]
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['users']);
$response = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::orderAsc('accessedAt')->toString()
]
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['users']);
}
public function testListUserMemberships(): void