Skip to content

Commit

Permalink
postgresql compatibility: update views with orm
Browse files Browse the repository at this point in the history
  • Loading branch information
ikolar authored and Nathan Wright committed Aug 19, 2010
1 parent a2740bd commit 24c7dac
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mediacore/model/media.py
Expand Up @@ -474,9 +474,6 @@ def increment_views(self):
self.views += 1
return self.views

query = 'UPDATE %s SET %s = (%s + 1) WHERE %s = :media_id' \
% (media, media.c.views, media.c.views, media.c.id)

# Don't raise an exception should concurrency problems occur.
# Views will not actually be incremented in this case, but thats
# relatively unimportant compared to rendering the page for the user.
Expand All @@ -487,7 +484,9 @@ def increment_views(self):
# media_fulltext's MyISAM engine must lock the whole table to do so.
transaction = DBSession.begin_nested()
try:
DBSession.execute(query, {'media_id': self.id}, self.__class__)
DBSession.query(self.__class__)\
.filter(self.__class__.id == self.id)\
.update({self.__class__.views: self.__class__.views + 1})
transaction.commit()
except exc.OperationalError, e:
transaction.rollback()
Expand Down

0 comments on commit 24c7dac

Please sign in to comment.