getsentry/sentry — pull request #1196 by umutgultepe (2014-06-03 02:05:17+00:00)
Title: Avoid unnecessary queries on next/previous events.

When running with a highly populated Postgresql database, the query for previous event takes unacceptably long time to fail if there are no previous instances (9-10 mins for our server).

With the .exists() condition, the time consuming query is not executed and we are able to view the new events without timing out.