Optimization: only request top sources if notification is to be sent

This commit is contained in:
Uku Taht 2021-11-08 15:38:37 +02:00
parent 945bf82c72
commit 42d70bf4ea
5 changed files with 27 additions and 10 deletions

6
.backup-env Normal file
View File

@ -0,0 +1,6 @@
CLICKHOUSE_PASSWORD=
S3_BUCKET=plausible-backups-test
S3_ACCESS_KEY=3KBJJYJN29XWX0R8D59M
S3_SECRET_KEY=WVIqTPPu76ZDMW7XlLeAVgU0FkNZeCwzapBN9slq
S3_ENDPOINT=s3.eu-central-1.wasabisys.com
REMOTE_STORAGE=s3

10
backup-config.yml Normal file
View File

@ -0,0 +1,10 @@
general:
remote_storage: s3
clickhouse:
username: default
password: ""
s3:
access_key: "3KBJJYJN29XWX0R8D59M"
secret_key: "WVIqTPPu76ZDMW7XlLeAVgU0FkNZeCwzapBN9slq"
bucket: "plausible-backups-test"
endpoint: "s3.eu-central-1.wasabisys.com"

View File

@ -21,23 +21,24 @@ defmodule Plausible.Workers.SpikeNotifier do
for notification <- notifications do
query = Query.from(notification.site.timezone, %{"period" => "realtime"})
current_visitors = clickhouse.current_visitors(notification.site, query)
sources = clickhouse.top_sources(notification.site, query, 3, 1, true)
notify(notification, current_visitors, sources)
if current_visitors >= notification.threshold do
sources = clickhouse.top_sources(notification.site, query, 3, 1, true)
notify(notification, current_visitors, sources)
end
end
:ok
end
def notify(notification, current_visitors, sources) do
if current_visitors >= notification.threshold do
for recipient <- notification.recipients do
send_notification(recipient, notification.site, current_visitors, sources)
end
notification
|> SpikeNotification.was_sent()
|> Repo.update()
for recipient <- notification.recipients do
send_notification(recipient, notification.site, current_visitors, sources)
end
notification
|> SpikeNotification.was_sent()
|> Repo.update()
end
defp send_notification(recipient, site, current_visitors, sources) do

BIN
pluralkit.me.events.ch Normal file

Binary file not shown.

BIN
pluralkit.me.sessions.ch Normal file

Binary file not shown.