From 3247b7c5d2359e13f83e7ec6a8cece22fe5a7c91 Mon Sep 17 00:00:00 2001 From: Jamil Date: Fri, 27 Jun 2025 12:06:45 -0700 Subject: [PATCH] fix(portal): don't log soft-deleted deletes (#9698) --- .../domain/change_logs/replication_connection.ex | 8 +++++++- .../change_logs/replication_connection_test.exs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/elixir/apps/domain/lib/domain/change_logs/replication_connection.ex b/elixir/apps/domain/lib/domain/change_logs/replication_connection.ex index 1d5a8852f..92242a19e 100644 --- a/elixir/apps/domain/lib/domain/change_logs/replication_connection.ex +++ b/elixir/apps/domain/lib/domain/change_logs/replication_connection.ex @@ -21,7 +21,13 @@ defmodule Domain.ChangeLogs.ReplicationConnection do end def on_delete(lsn, table, old_data) do - log(:delete, lsn, table, old_data, nil) + if is_nil(old_data["deleted_at"]) do + log(:delete, lsn, table, old_data, nil) + else + # Avoid overwhelming the change log with soft-deleted records getting hard-deleted en masse. + # Can be removed after https://github.com/firezone/firezone/issues/8187 is shipped. + :ok + end end # Relay group tokens don't have account_ids diff --git a/elixir/apps/domain/test/domain/change_logs/replication_connection_test.exs b/elixir/apps/domain/test/domain/change_logs/replication_connection_test.exs index 5c4049d6f..87d3dbd0f 100644 --- a/elixir/apps/domain/test/domain/change_logs/replication_connection_test.exs +++ b/elixir/apps/domain/test/domain/change_logs/replication_connection_test.exs @@ -140,6 +140,19 @@ defmodule Domain.ChangeLogs.ReplicationConnectionTest do end describe "on_delete/2" do + test "ignores soft-deleted records" do + table = "resources" + old_data = %{"id" => Ecto.UUID.generate(), "deleted_at" => "#{DateTime.utc_now()}"} + + initial_count = Repo.aggregate(ChangeLog, :count, :id) + + assert :ok = on_delete(0, table, old_data) + + # No record should be created for soft-deleted records + final_count = Repo.aggregate(ChangeLog, :count, :id) + assert final_count == initial_count + end + test "ignores flows table - no record created" do table = "flows" old_data = %{"id" => 1, "name" => "deleted flow"}