Skip to content
Browse files

Reduce the possibility of deadlocks when incrementing media view counts

  • Loading branch information...
1 parent 5eb9d49 commit 9ef359607000380f082365aea00f7c59f3a1b5cc @natedub natedub committed with anthonyt
Showing with 6 additions and 2 deletions.
  1. +6 −2 mediacore/controllers/
8 mediacore/controllers/
@@ -27,6 +27,7 @@
from pylons import app_globals, config, request, response
from pylons.controllers.util import forward
from sqlalchemy import orm, sql
+from sqlalchemy.exc import OperationalError
from webob.exc import HTTPNotAcceptable, HTTPNotFound
from mediacore import USER_AGENT
@@ -161,7 +162,6 @@ def random(self, **kwargs):
redirect(action='view', slug=media.slug, podcast_slug=podcast_slug)
- @autocommit
def view(self, slug, podcast_slug=None, **kwargs):
"""Display the media player, info and comments.
@@ -199,7 +199,11 @@ def view(self, slug, podcast_slug=None, **kwargs):
if url_for() != url_for(podcast_slug=media.podcast.slug):
- media.increment_views()
+ try:
+ media.increment_views()
+ DBSession.commit()
+ except OperationalError:
+ DBSession.rollback()
# TODO: finish implementation of different 'likes' buttons
# e.g. the default one, plus a setting to use facebook.

0 comments on commit 9ef3596

Please sign in to comment.
Something went wrong with that request. Please try again.