Skip to content

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

increase api_keys.hourly_request_limit in CE (#4200)

ruslandoga22ea56a77934
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eee8df8830..559d559fa2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
### Changed
+- Increase hourly request limit for API keys in CE from 600 to 1000000 (practically removing the limit) plausible/analytics#4200
+
### Fixed
## v2.1.1 - 2024-06-06
diff --git a/lib/plausible/auth/api_key.ex b/lib/plausible/auth/api_key.ex
index 78fa5b3a93..e52810dcf9 100644
--- a/lib/plausible/auth/api_key.ex
+++ b/lib/plausible/auth/api_key.ex
@@ -1,4 +1,5 @@
defmodule Plausible.Auth.ApiKey do
+ use Plausible
use Ecto.Schema
import Ecto.Changeset
@@ -9,7 +10,7 @@ defmodule Plausible.Auth.ApiKey do
schema "api_keys" do
field :name, :string
field :scopes, {:array, :string}, default: ["stats:read:*"]
- field :hourly_request_limit, :integer, default: 600
+ field :hourly_request_limit, :integer, default: on_ee(do: 600, else: 1_000_000)
field :key, :string, virtual: true
field :key_hash, :string
diff --git a/test/plausible/auth/auth_test.exs b/test/plausible/auth/auth_test.exs
index 0367dfe763..95f4ae588c 100644
--- a/test/plausible/auth/auth_test.exs
+++ b/test/plausible/auth/auth_test.exs
@@ -57,6 +57,26 @@ defmodule Plausible.AuthTest do
assert {:ok, %Auth.ApiKey{}} = Auth.create_api_key(user, "my new key", key)
end
+ @tag :ee_only
+ test "defaults to 600 requests per hour limit in EE" do
+ user = insert(:user)
+
+ {:ok, %Auth.ApiKey{hourly_request_limit: hourly_request_limit}} =
+ Auth.create_api_key(user, "my new EE key", Ecto.UUID.generate())
+
+ assert hourly_request_limit == 600
+ end
+
+ @tag :ce_build_only
+ test "defaults to 1000000 requests per hour limit in CE" do
+ user = insert(:user)
+
+ {:ok, %Auth.ApiKey{hourly_request_limit: hourly_request_limit}} =
+ Auth.create_api_key(user, "my new CE key", Ecto.UUID.generate())
+
+ assert hourly_request_limit == 1_000_000
+ end
+
test "errors when key already exists" do
u1 = insert(:user)
u2 = insert(:user)