Skip to content

Commit

Permalink
[bug 701011] fix excerpt problems
Browse files Browse the repository at this point in the history
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
willkg committed Nov 9, 2011
1 parent 1ac25ba commit 97041af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions apps/search/__init__.py
Expand Up @@ -86,4 +86,6 @@ def port(self):
else settings.SPHINX_PORT)


ExcerptTimeoutError = oedipus.ExcerptTimeoutError
ExcerptSocketErrorError = oedipus.ExcerptSocketErrorError
SearchError = oedipus.SearchError
27 changes: 22 additions & 5 deletions apps/search/views.py
Expand Up @@ -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
Expand Down Expand Up @@ -307,8 +308,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,
Expand All @@ -325,8 +334,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,
Expand Down
2 changes: 1 addition & 1 deletion vendor/src/oedipus
Submodule oedipus updated 1 files
+32 −9 oedipus/__init__.py

0 comments on commit 97041af

Please sign in to comment.