-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report for estimated count of notifications_users records (#2216)
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters