Permalink
Browse files

[bug 701011] fix excerpt problems

The old search view code caught socket.timeout and socket.error exceptions
and handled them.  The new code in oedipus didn't.  Turns out these errors
happen a lot in production.

This adds handling for those errors and also counts them with
statsd so we can see how big the problem is without getting a ton of
error email.
  • Loading branch information...
1 parent 26302fe commit 66ba9bdf67942f834bca216c377c7eecbb2a755e @willkg willkg committed Nov 9, 2011
Showing with 25 additions and 6 deletions.
  1. +2 −0 apps/search/__init__.py
  2. +22 −5 apps/search/views.py
  3. +1 −1 vendor/src/oedipus
@@ -86,4 +86,6 @@ def port(self):
else settings.SPHINX_PORT)
+ExcerptTimeoutError = oedipus.ExcerptTimeoutError
+ExcerptSocketErrorError = oedipus.ExcerptSocketErrorError
SearchError = oedipus.SearchError
View
@@ -14,9 +14,10 @@
import jingo
import jinja2
from mobility.decorators import mobile_template
+from statsd import statsd
from tower import ugettext as _
-from search import SearchError
+from search import SearchError, ExcerptTimeoutError, ExcerptSocketErrorError
from search.utils import locale_or_default, clean_excerpt
from forums.models import Thread, discussion_search
from questions.models import question_search
@@ -311,8 +312,16 @@ def search(request, template=None):
results.append(result)
elif type_ == 'question':
- summary = jinja2.Markup(
- clean_excerpt(question_s.excerpt(doc)[0]))
+ try:
+ excerpt = question_s.excerpt(doc)[0]
+ except ExcerptTimeoutError:
+ statsd.incr('search.excerpt.timeout')
+ excerpt = u''
+ except ExcerptSocketErrorError:
+ statsd.incr('search.excerpt.socketerror')
+ excerpt = u''
+
+ summary = jinja2.Markup(clean_excerpt(excerpt))
result = {
'search_summary': summary,
@@ -329,8 +338,16 @@ def search(request, template=None):
# to get this manually.
thread = Thread.objects.get(pk=doc.thread_id)
- summary = jinja2.Markup(
- clean_excerpt(discussion_s.excerpt(doc)[0]))
+ try:
+ excerpt = discussion_s.excerpt(doc)[0]
+ except ExcerptTimeoutError:
+ statsd.incr('search.excerpt.timeout')
+ excerpt = u''
+ except ExcerptSocketErrorError:
+ statsd.incr('search.excerpt.socketerror')
+ excerpt = u''
+
+ summary = jinja2.Markup(clean_excerpt(excerpt))
result = {
'search_summary': summary,
Submodule oedipus updated 1 files
+32 −9 oedipus/__init__.py

0 comments on commit 66ba9bd

Please sign in to comment.