mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 20:13:31 +03:00
Optimization: only request top sources if notification is to be sent
This commit is contained in:
parent
945bf82c72
commit
42d70bf4ea
6
.backup-env
Normal file
6
.backup-env
Normal 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
10
backup-config.yml
Normal 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"
|
@ -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
BIN
pluralkit.me.events.ch
Normal file
Binary file not shown.
BIN
pluralkit.me.sessions.ch
Normal file
BIN
pluralkit.me.sessions.ch
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user