mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
refactor(mqtt): inject cache resolver and planForUser into the handler
The handler no longer service-locates getCache/getPlanForUser off the container by string key; both arrive as typed constructor params. The cache stays a resolver closure because the pool-backed cache can only be built inside a coroutine, so it is resolved lazily per coroutine as before.
This commit is contained in:
1 parent
5b997eee6a
commit
675448d48f
2 files changed
+6
-7
No files matched your search
+1
-1
@@ -184,7 +184,7 @@ $mqtt = new Mqtt($telemetry, new PubSubPool($register->get('pools')->get('pubsub
|
||||
|
||||
// The broker owns framing, decoding, dispatch, per-version encoding, packet ids, the QoS
|
||||
// handshake, keep-alive reaping and subscription matching. Appwrite policy lives in the Handler.
|
||||
$handler = new Handler($container, $mqtt);
|
||||
$handler = new Handler($container, $mqtt, $container->get('getCache'), $container->get('getPlanForUser'));
|
||||
$server = new Server($adapter, $handler);
|
||||
$server->setTelemetry($telemetry); // broker owns connection/packet/subscription metrics
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ class Handler implements MqttHandler
|
||||
public function __construct(
|
||||
private readonly Container $container,
|
||||
private readonly Mqtt $mqtt,
|
||||
private readonly \Closure $getCache,
|
||||
private readonly \Closure $planForUser,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -227,8 +229,7 @@ class Handler implements MqttHandler
|
||||
$this->mqtt->messagesAcked->add(1);
|
||||
$this->mqtt->pubacksReceived->add(1);
|
||||
|
||||
$getCache = $this->container->get('getCache');
|
||||
$cache = $getCache();
|
||||
$cache = ($this->getCache)();
|
||||
$key = $this->cursorKey($connection);
|
||||
$topic = $delivery['topic'];
|
||||
$cursor = (int) $delivery['cursor'];
|
||||
@@ -274,11 +275,9 @@ class Handler implements MqttHandler
|
||||
*/
|
||||
private function replayBacklog(Connection $connection, Database $projectDB, array $grantedTopics): void
|
||||
{
|
||||
$getCache = $this->container->get('getCache');
|
||||
$getPlanForUser = $this->container->get('getPlanForUser');
|
||||
$cache = $getCache();
|
||||
$cache = ($this->getCache)();
|
||||
$key = $this->cursorKey($connection);
|
||||
$maxDepth = max(1, $getPlanForUser(new Document(['$id' => $connection->prefix]), $connection->identity['userId'] ?? ''));
|
||||
$maxDepth = max(1, ($this->planForUser)(new Document(['$id' => $connection->prefix]), $connection->identity['userId'] ?? ''));
|
||||
|
||||
$expiry = 0;
|
||||
foreach ($grantedTopics as [$document]) {
|
||||
|
||||
Reference in new issue
Block a user