Skip to content

Commit

Permalink
fix realtime with db refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Oct 7, 2021
1 parent 42414e8 commit a585a90
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 233 deletions.
51 changes: 50 additions & 1 deletion app/config/collections2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,56 @@
'orders' => [Database::ORDER_DESC],
],
],
]
],
'realtime' => [
'$collection' => Database::METADATA,
'$id' => 'realtime',
'name' => 'Realtime Connections',
'attributes' => [
[
'$id' => 'container',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => true,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'timestamp',
'type' => Database::VAR_INTEGER,
'format' => '',
'size' => 0,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'value',
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16384,
'signed' => true,
'required' => true,
'default' => null,
'array' => false,
'filters' => [], //TODO: use json filter
]
],
'indexes' => [
[
'$id' => '_key_timestamp',
'type' => Database::INDEX_KEY,
'attributes' => ['timestamp'],
'lengths' => [],
'orders' => [Database::ORDER_DESC],
],
]
],
];

return $collections;
4 changes: 2 additions & 2 deletions app/controllers/api/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@
]));

Authorization::reset();

$jwt = ''; // initialize
if (!$user->isEmpty()) { // If userId exists, generate a JWT for function

$sessions = $user->getAttribute('sessions', []);
$current = new Document();

Expand Down
20 changes: 10 additions & 10 deletions app/controllers/shared/api.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use Appwrite\Auth\Auth;
use Appwrite\Database\Document;
use Appwrite\Database\Validator\Authorization;
use Appwrite\Messaging\Adapter\Realtime;
use Utopia\App;
use Utopia\Exception;
use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit;
use Utopia\Database\Document;
use Utopia\Storage\Device\Local;
use Utopia\Storage\Storage;

Expand Down Expand Up @@ -209,37 +209,37 @@
$target = Realtime::fromPayload($events->getParam('event'), $payload);

Realtime::send(
$project->getId(),
$response->getPayload(),
$events->getParam('event'),
$target['channels'],
$target['roles'],
$project->getId(),
$response->getPayload(),
$events->getParam('event'),
$target['channels'],
$target['roles'],
[
'permissionsChanged' => $target['permissionsChanged'],
'userId' => $events->getParam('userId')
]
);
}
}

if (!empty($audits->getParam('event'))) {
$audits->trigger();
}

if (!empty($deletes->getParam('type')) && !empty($deletes->getParam('document'))) {
$deletes->trigger();
}

if (!empty($database->getParam('type')) && !empty($database->getParam('document'))) {
$database->trigger();
}

$route = $utopia->match($request);
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled'
&& $project->getId()
&& $mode !== APP_MODE_ADMIN // TODO: add check to make sure user is admin
&& !empty($route->getLabel('sdk.namespace', null))) { // Don't calculate console usage on admin mode

$usage
->setParam('networkRequestSize', $request->getSize() + $usage->getParam('storage'))
->setParam('networkResponseSize', $response->getSize())
Expand Down
1 change: 0 additions & 1 deletion app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
}

$dbForConsole->createCollection($key, $attributes, $indexes);

}

Console::success('[Setup] - Server database init completed...');
Expand Down
2 changes: 0 additions & 2 deletions app/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
use Appwrite\Network\Validator\Email;
use Appwrite\Network\Validator\IP;
use Appwrite\Network\Validator\URL;
use Appwrite\Event\Realtime;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Stats\Stats;
use Utopia\App;
use Utopia\CLI\Console;
use Utopia\View;
use Utopia\Config\Config;
use Utopia\Locale\Locale;
Expand Down
Loading

0 comments on commit a585a90

Please sign in to comment.