Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

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

Uku Taht42d70bf4ea37
diff --git a/.backup-env b/.backup-env
new file mode 100644
index 0000000000..44eb6e496a
--- /dev/null
+++ b/.backup-env
@@ -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
diff --git a/backup-config.yml b/backup-config.yml
new file mode 100644
index 0000000000..e525c88aa3
--- /dev/null
+++ b/backup-config.yml
@@ -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"
diff --git a/lib/workers/spike_notifier.ex b/lib/workers/spike_notifier.ex
index bac715adf0..4582536156 100644
--- a/lib/workers/spike_notifier.ex
+++ b/lib/workers/spike_notifier.ex
@@ -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
diff --git a/pluralkit.me.events.ch b/pluralkit.me.events.ch
new file mode 100644
index 0000000000..438b6558d2
Binary files /dev/null and b/pluralkit.me.events.ch differ
diff --git a/pluralkit.me.sessions.ch b/pluralkit.me.sessions.ch
new file mode 100644
index 0000000000..01c4c6662d
Binary files /dev/null and b/pluralkit.me.sessions.ch differ