Skip to content
This repository
Browse code

Reduce the possibility of deadlocks when incrementing media view counts

  • Loading branch information...
commit 9ef359607000380f082365aea00f7c59f3a1b5cc 1 parent 5eb9d49
Nathan Wright authored July 21, 2011 anthonyt committed January 05, 2012

Showing 1 changed file with 6 additions and 2 deletions. Show diff stats Hide diff stats

  1. 8  mediacore/controllers/media.py
8  mediacore/controllers/media.py
@@ -27,6 +27,7 @@
27 27
 from pylons import app_globals, config, request, response
28 28
 from pylons.controllers.util import forward
29 29
 from sqlalchemy import orm, sql
  30
+from sqlalchemy.exc import OperationalError
30 31
 from webob.exc import HTTPNotAcceptable, HTTPNotFound
31 32
 
32 33
 from mediacore import USER_AGENT
@@ -161,7 +162,6 @@ def random(self, **kwargs):
161 162
         redirect(action='view', slug=media.slug, podcast_slug=podcast_slug)
162 163
 
163 164
     @expose('media/view.html')
164  
-    @autocommit
165 165
     @observable(events.MediaController.view)
166 166
     def view(self, slug, podcast_slug=None, **kwargs):
167 167
         """Display the media player, info and comments.
@@ -199,7 +199,11 @@ def view(self, slug, podcast_slug=None, **kwargs):
199 199
             if url_for() != url_for(podcast_slug=media.podcast.slug):
200 200
                 redirect(podcast_slug=media.podcast.slug)
201 201
 
202  
-        media.increment_views()
  202
+        try:
  203
+            media.increment_views()
  204
+            DBSession.commit()
  205
+        except OperationalError:
  206
+            DBSession.rollback()
203 207
 
204 208
         # TODO: finish implementation of different 'likes' buttons
205 209
         #       e.g. the default one, plus a setting to use facebook.

0 notes on commit 9ef3596

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