Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Fix: record seed crawls where outcome is scheduled

blueheron786ae8107fee4eb
diff --git a/mwmbl/tinysearchengine/combined_search.py b/mwmbl/tinysearchengine/combined_search.py
index a7d37c6..fad88b0 100644
--- a/mwmbl/tinysearchengine/combined_search.py
+++ b/mwmbl/tinysearchengine/combined_search.py
@@ -310,10 +310,11 @@ def init_router(ranker) -> None:
crawl_outcome = None
active_crawl_query = None
if crawl:
- await sync_to_async(record_seed_search)(user.id)
crawl_outcome = await sync_to_async(start_seed_crawl)(
user.id, q, retrieval.pages, staan_results, new_staan_urls
)
+ if crawl_outcome == CrawlOutcome.SCHEDULED:
+ await sync_to_async(record_seed_search)(user.id)
if crawl_outcome == CrawlOutcome.ALREADY_RUNNING:
active_crawl_query = await sync_to_async(get_active_seed_crawl_query)(user.id)
diff --git a/test/test_combined_search.py b/test/test_combined_search.py
index 3ee67a0..e12713e 100644
--- a/test/test_combined_search.py
+++ b/test/test_combined_search.py
@@ -566,6 +566,20 @@ def test_a_seed_search_counts_itself_in_the_users_total(
assert user.seed_searches == 1
+def test_a_seed_search_that_cannot_start_a_crawl_is_not_counted(
+ client, user, access_token, fresh_quota, redis_cache, crawl_sources
+):
+ crawl_sources()
+ _crawl(client, access_token, query="tokio")
+
+ body = _crawl(client, access_token, query="rust").json()
+ user.refresh_from_db()
+
+ assert body["crawl_outcome"] == "already_running"
+ assert user.seed_searches == 1
+
+
@pytest.mark.django_db
def test_a_search_without_the_crawl_flag_is_not_counted(client, user, access_token, fresh_quota, stub_sources):
stub_sources(new_urls=("https://a.example/",))