From 3c1e30a785b479fcce8b0c35fd645b59352378f9 Mon Sep 17 00:00:00 2001 From: Chase Granberry Date: Tue, 22 Aug 2023 12:13:40 -0700 Subject: [PATCH 1/2] fix: dont count Presence state message --- lib/realtime_web/channels/realtime_channel.ex | 9 +++++++++ mix.exs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/realtime_web/channels/realtime_channel.ex b/lib/realtime_web/channels/realtime_channel.ex index 504e3b873..004d828a9 100644 --- a/lib/realtime_web/channels/realtime_channel.ex +++ b/lib/realtime_web/channels/realtime_channel.ex @@ -255,6 +255,15 @@ defmodule RealtimeWeb.RealtimeChannel do {:noreply, socket} end + def handle_info(%{event: "presence_state" = type, payload: payload} = msg, socket) do + # TODO: don't use Presence in a RealtimeChannel if client does not want it + # Don't count Presence state because we bill for things we're counting and we're using Presence even if people don't want to + socket = socket |> maybe_log_handle_info(msg) + + push(socket, type, payload) + {:noreply, socket} + end + @impl true def handle_info( :postgres_subscribe, diff --git a/mix.exs b/mix.exs index a2af1d016..893d57202 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do def project do [ app: :realtime, - version: "2.21.0", + version: "2.21.1", elixir: "~> 1.14.0", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, From 6f54f64587552b9f897ff753c6e14c5463db9758 Mon Sep 17 00:00:00 2001 From: Chase Granberry Date: Tue, 22 Aug 2023 12:35:39 -0700 Subject: [PATCH 2/2] fix: actually don't count "presence state" messages now --- lib/realtime_web/channels/realtime_channel.ex | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/realtime_web/channels/realtime_channel.ex b/lib/realtime_web/channels/realtime_channel.ex index 004d828a9..2c37fdf67 100644 --- a/lib/realtime_web/channels/realtime_channel.ex +++ b/lib/realtime_web/channels/realtime_channel.ex @@ -233,7 +233,10 @@ defmodule RealtimeWeb.RealtimeChannel do @impl true def handle_info(:sync_presence = msg, %{assigns: %{tenant_topic: topic}} = socket) do - socket = socket |> count() |> maybe_log_handle_info(msg) + # TODO: don't use Presence unless client explicitly wants to use Presence + # TODO: count these again when that happens + + socket = socket |> maybe_log_handle_info(msg) push(socket, "presence_state", presence_dirty_list(topic)) @@ -255,15 +258,6 @@ defmodule RealtimeWeb.RealtimeChannel do {:noreply, socket} end - def handle_info(%{event: "presence_state" = type, payload: payload} = msg, socket) do - # TODO: don't use Presence in a RealtimeChannel if client does not want it - # Don't count Presence state because we bill for things we're counting and we're using Presence even if people don't want to - socket = socket |> maybe_log_handle_info(msg) - - push(socket, type, payload) - {:noreply, socket} - end - @impl true def handle_info( :postgres_subscribe,