Skip to content

Commit

Permalink
feat: report for estimated count of notifications_users records (#2216)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald authored Sep 12, 2023
1 parent 8e29c23 commit f362d89
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule Report do
Report.UserSettings,
Report.UserNamesAndUuids,
Report.UserConfigurations,
Report.NotificationsCountEstimate
Report.NotificationsCountEstimate,
Report.NotificationsUsersCountEstimate
]

@callback run() :: {:ok, [map()]} | :error
Expand Down
24 changes: 24 additions & 0 deletions lib/report/notifications_users_count_estimate.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Report.NotificationsUsersCountEstimate do
@moduledoc """
Returns the Postgres estimated count of entries in the notifications table,
for evaluating options to delete old entries
"""
import Ecto.Query

@behaviour Report

@impl Report
def run() do
[count] =
from(p in "pg_class", where: p.relname == "notifications_users", select: p.reltuples)
|> Skate.Repo.all()

{:ok, [%{count: count}]}
end

@impl Report
def short_name(), do: "notifications_users_count_estimate"

@impl Report
def description(), do: "Estimated count of notifications_users"
end
27 changes: 27 additions & 0 deletions test/report/notifications_users_count_estimate_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Report.NotificationsUsersCountEstimateTest do
use Skate.DataCase

describe "run/0" do
test "returns a single-row numeric value" do
{:ok, result} = Report.NotificationsUsersCountEstimate.run()

assert [%{count: count}] = result

assert is_number(count)
end
end

describe "short_name/0" do
test "returns short name" do
assert Report.NotificationsUsersCountEstimate.short_name() ==
"notifications_users_count_estimate"
end
end

describe "description/0" do
test "returns description" do
assert Report.NotificationsUsersCountEstimate.description() ==
"Estimated count of notifications_users"
end
end
end
3 changes: 2 additions & 1 deletion test/report_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ defmodule ReportTest do
"user_configurations" => Report.UserConfigurations,
"user_settings" => Report.UserSettings,
"user_names_and_uuids" => Report.UserNamesAndUuids,
"notifications_count_estimate" => Report.NotificationsCountEstimate
"notifications_count_estimate" => Report.NotificationsCountEstimate,
"notifications_users_count_estimate" => Report.NotificationsUsersCountEstimate
}
end
end
Expand Down

0 comments on commit f362d89

Please sign in to comment.