mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #12805 from appwrite/limit-ping-counts
Limit ping counts
This commit is contained in:
2 files changed
+11
-16
No files matched your search
@@ -1691,22 +1691,17 @@ Http::get('/v1/ping')
|
||||
}
|
||||
|
||||
$pingCount = $project->getAttribute('pingCount', 0) + 1;
|
||||
$pingedAt = DateTime::now();
|
||||
|
||||
$project
|
||||
->setAttribute('pingCount', $pingCount)
|
||||
->setAttribute('pingedAt', $pingedAt);
|
||||
if ($pingCount === 1) {
|
||||
$project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([
|
||||
'pingCount' => $pingCount,
|
||||
'pingedAt' => DateTime::now(),
|
||||
])));
|
||||
|
||||
$authorization->skip(function () use ($dbForPlatform, $project) {
|
||||
$dbForPlatform->updateDocument('projects', $project->getId(), new Document([
|
||||
'pingCount' => $project->getAttribute('pingCount'),
|
||||
'pingedAt' => $project->getAttribute('pingedAt')
|
||||
]));
|
||||
});
|
||||
|
||||
$queueForEvents
|
||||
->setParam('projectId', $project->getId())
|
||||
->setPayload($response->output($project, Response::MODEL_PROJECT));
|
||||
$queueForEvents
|
||||
->setParam('projectId', $project->getId())
|
||||
->setPayload($response->output($project, Response::MODEL_PROJECT));
|
||||
}
|
||||
|
||||
$response->text('Pong!');
|
||||
});
|
||||
|
||||
@@ -836,7 +836,7 @@ final class ProjectsConsoleClientTest extends Scope
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$id = $response['body']['$id'];
|
||||
|
||||
// Increase ping 3x
|
||||
// Ping 3x; only the first is recorded, so pingCount stays at 1
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$response = $this->client->call(
|
||||
Client::METHOD_GET,
|
||||
@@ -1113,7 +1113,7 @@ final class ProjectsConsoleClientTest extends Scope
|
||||
$this->assertSame('', $response['body']['smtpUsername']);
|
||||
$this->assertSame('', $response['body']['smtpPassword']); // Write only
|
||||
$this->assertSame('', $response['body']['smtpSecure']);
|
||||
$this->assertSame(3, $response['body']['pingCount']);
|
||||
$this->assertSame(1, $response['body']['pingCount']);
|
||||
|
||||
$this->assertIsString($response['body']['pingedAt']);
|
||||
$this->assertNotEmpty($response['body']['pingedAt']);
|
||||
|
||||
Reference in new issue
Block a user