diff --git a/app.py b/app.py index afcf052..355ec35 100644 --- a/app.py +++ b/app.py @@ -288,6 +288,10 @@ def search(): except InvalidQueryException as e: flash("Invalid query: " + str(e), "warning") return redirect("/search") + except Exception: + flash("Query failed, this could mean that the search server is overloaded or is not reachable. " + "Please try again later", "danger") + hits = None else: hits = None @@ -313,9 +317,13 @@ def contribute(): @app.route("/") @cache.cached(240) def home(): - stats = searchEngine.get_global_stats() - stats["website_count"] = len(db.get_all_websites()) - current_websites = ", ".join(task.url for task in taskDispatcher.get_current_tasks()) + try: + stats = searchEngine.get_global_stats() + stats["website_count"] = len(db.get_all_websites()) + current_websites = ", ".join(task.url for task in taskDispatcher.get_current_tasks()) + except: + stats = {} + current_websites = None return render_template("home.html", stats=stats, current_websites=current_websites) diff --git a/search/search.py b/search/search.py index 33f6a7b..10b39eb 100644 --- a/search/search.py +++ b/search/search.py @@ -238,7 +238,7 @@ class ElasticSearchEngine(SearchEngine): } }, "size": 0 - }, index=self.index_name, request_timeout=30) + }, index=self.index_name, request_timeout=20) stats = dict() stats["total_size"] = result["aggregations"]["total_size"]["value"] @@ -260,7 +260,7 @@ class ElasticSearchEngine(SearchEngine): "website_id": website_id} } }, - index=self.index_name, request_timeout=30) + index=self.index_name, request_timeout=20) for hit in hits: src = hit["_source"] yield base_url + src["path"] + ("/" if src["path"] != "" else "") + src["name"] + \ @@ -295,7 +295,7 @@ class ElasticSearchEngine(SearchEngine): }, "size": 0 - }, index=self.index_name, request_timeout=30) + }, index=self.index_name, request_timeout=20) total_stats = self.es.search(body={ "query": { @@ -317,7 +317,7 @@ class ElasticSearchEngine(SearchEngine): }, "size": 0 - }, index=self.index_name, request_timeout=30) + }, index=self.index_name, request_timeout=20) size_and_date_histogram = self.es.search(body={ "query": { @@ -352,7 +352,7 @@ class ElasticSearchEngine(SearchEngine): } }, "size": 0 - }, index=self.index_name, request_timeout=30) + }, index=self.index_name, request_timeout=20) website_scatter = self.es.search(body={ "query": { @@ -380,9 +380,9 @@ class ElasticSearchEngine(SearchEngine): } }, "size": 0 - }, index=self.index_name, request_timeout=30) + }, index=self.index_name, request_timeout=20) - es_stats = self.es.indices.stats(self.index_name, request_timeout=30) + es_stats = self.es.indices.stats(self.index_name, request_timeout=20) stats = dict() stats["es_index_size"] = es_stats["indices"][self.index_name]["total"]["store"]["size_in_bytes"] diff --git a/templates/home.html b/templates/home.html index 63b4fae..f011158 100644 --- a/templates/home.html +++ b/templates/home.html @@ -11,9 +11,12 @@ {% if stats and stats["total_size"] %}
{{ stats["total_count"] }} files totalling ~{{ stats["total_size"] | filesizeformat }} from {{ stats["website_count"] }} websites
- {% endif %} - {% if current_websites %} -Currently indexing {{ current_websites }}
Currently indexing {{ current_websites }}
We're currently experiencing a high volume of traffic. The search function + may be unresponsive.
{% endif %}