Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Keep every Combined Search limit, free included, in one settings dict

Claude9b59ccfdccbb
diff --git a/mwmbl/membership.py b/mwmbl/membership.py
index 4f98519..040ac2e 100644
--- a/mwmbl/membership.py
+++ b/mwmbl/membership.py
@@ -59,14 +59,6 @@ def tier_for_product(product_id: str) -> MembershipTier | None:
return tiers_by_product.get(product_id)
-# Combined Search queries a month for web (JWT) callers, by tier. Signed-in users without a
-# membership get COMBINED_SEARCH_MONTHLY_LIMIT.
-COMBINED_SEARCH_MONTHLY_LIMITS = {
- MembershipTier.SPROUT: 300,
- MembershipTier.SAPLING: 1_500,
- MembershipTier.CANOPY: 1_500,
-}
-
-
def combined_search_monthly_limit(tier: str | None) -> int:
- return COMBINED_SEARCH_MONTHLY_LIMITS.get(tier, settings.COMBINED_SEARCH_MONTHLY_LIMIT)
+ """Combined Search queries a month for a web (JWT) caller with this membership tier."""
+ return settings.COMBINED_SEARCH_MONTHLY_LIMITS[tier or "free"]
diff --git a/mwmbl/settings_common.py b/mwmbl/settings_common.py
index c8cc4dc..3901a9a 100644
--- a/mwmbl/settings_common.py
+++ b/mwmbl/settings_common.py
@@ -290,9 +290,9 @@ CURRENT_AGREEMENT_VERSIONS = {
# Combined Search - the v2 endpoint that pools the Mwmbl index, Staan and Wikipedia and
# ranks the union with its own LTR model. Gated behind login, like Super Search, which it is
-# meant to replace. This is the monthly limit for signed-in users without a membership;
-# member tiers get more - see mwmbl.membership.COMBINED_SEARCH_MONTHLY_LIMITS.
-COMBINED_SEARCH_MONTHLY_LIMIT = 30
+# meant to replace. Monthly limits for web (JWT) callers, keyed by
+# mwmbl.membership.MembershipTier value; "free" is signed-in users without a membership.
+COMBINED_SEARCH_MONTHLY_LIMITS = {"free": 30, "sprout": 300, "sapling": 1_500, "canopy": 1_500}
# Its own model artifact, so Combined Search can be retrained on the pooled candidate set
# without moving standard search's ranking. Falls back to RUST_MODEL_PATH until trained.
COMBINED_MODEL_PATH = Path(__file__).parent / "resources" / "model-combined.xgb"
diff --git a/test/test_combined_search.py b/test/test_combined_search.py
index b2b0250..960fa8d 100644
--- a/test/test_combined_search.py
+++ b/test/test_combined_search.py
@@ -160,7 +160,7 @@ def test_an_api_key_is_refused_until_keyed_access_is_billed(client, api_key, fre
@pytest.mark.django_db
-@override_settings(COMBINED_SEARCH_MONTHLY_LIMIT=10)
+@override_settings(COMBINED_SEARCH_MONTHLY_LIMITS={"free": 10})
def test_the_response_reports_the_quota(client, access_token, fresh_quota, stub_sources):
stub_sources()
@@ -171,7 +171,7 @@ def test_the_response_reports_the_quota(client, access_token, fresh_quota, stub_
@pytest.mark.django_db
-@override_settings(COMBINED_SEARCH_MONTHLY_LIMIT=10)
+@override_settings(COMBINED_SEARCH_MONTHLY_LIMITS={"free": 10})
def test_combined_search_quota_enforced(client, user, access_token, fresh_quota, stub_sources):
stub_sources()
cache.set(_combined_search_monthly_key(user.id), 10, timeout=3600)
@@ -180,7 +180,7 @@ def test_combined_search_quota_enforced(client, user, access_token, fresh_quota,
@pytest.mark.django_db
-@override_settings(COMBINED_SEARCH_MONTHLY_LIMIT=10)
+@override_settings(COMBINED_SEARCH_MONTHLY_LIMITS={"free": 10})
def test_a_rejected_request_refunds_its_increment(client, user, access_token, fresh_quota, stub_sources):
"""The counter is incremented before it is checked, so that concurrent requests cannot
both pass. A rejected request must give that increment back, or being over the limit
@@ -195,7 +195,7 @@ def test_a_rejected_request_refunds_its_increment(client, user, access_token, fr
@pytest.mark.django_db
-@override_settings(COMBINED_SEARCH_MONTHLY_LIMIT=10)
+@override_settings(COMBINED_SEARCH_MONTHLY_LIMITS={"free": 10})
def test_the_quota_counter_is_its_own(client, user, access_token, fresh_quota, stub_sources):
"""Combined Search must not spend the standard-search or Super Search allowance."""
from mwmbl.quota import get_monthly_count, get_monthly_super_search_count