Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 6c96bb8

Browse files
committed
wip
1 parent 5c93909 commit 6c96bb8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Statistics/Logger/HttpStatisticsLogger.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function disconnection(ConnectionInterface $connection)
5757

5858
protected function findOrMakeStatisticForAppId($appId): Statistic
5959
{
60-
if (! isset($this->statistics[$appId])) {
60+
if (!isset($this->statistics[$appId])) {
6161
$this->statistics[$appId] = new Statistic($appId);
6262
}
6363

@@ -68,23 +68,19 @@ public function save()
6868
{
6969
foreach ($this->statistics as $appId => $statistic) {
7070

71-
if (! $statistic->isEnabled()) {
71+
if (!$statistic->isEnabled()) {
7272
continue;
7373
}
7474

75-
$this->browser
75+
$this
76+
->browser
7677
->post(
7778
action([WebSocketStatisticsEntriesController::class, 'store']),
7879
['Content-Type' => 'application/json'],
7980
stream_for(json_encode($statistic->toArray()))
8081
);
8182

82-
// Reset connection and message count
83-
$currentConnectionCount = collect($this->channelManager->getChannels($appId))
84-
->sum(function ($channel) {
85-
return count($channel->getSubscribedConnections());
86-
});
87-
83+
$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
8884
$statistic->reset($currentConnectionCount);
8985
}
9086
}

src/WebSockets/Channels/ChannelManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public function getChannels(string $appId): array
4646
return $this->channels[$appId] ?? [];
4747
}
4848

49+
public function getConnectionCount(string $appId): int
50+
{
51+
return collect($this->getChannels($appId))
52+
->sum->getSubscribedConnections();
53+
}
54+
4955
public function removeFromAllChannels(ConnectionInterface $connection)
5056
{
5157
if (!isset($connection->app)) {

0 commit comments

Comments
 (0)