Commits

Miki Tebeka committed 01954be

Update hits

Comments (0)

Files changed (1)

     '''Get a Url from datastore by short url.'''
     return Url.get_by_key_name(short_url)
 
+def inc_hits(short_url):
+    '''Increment hits on a url.'''
+
+    # Transaction function
+    def txn():
+        url = get_url(short_url)
+        if not url:
+            log.error('inc_hits - {0} not found'.format(short_url))
+            return
+        url.hits += 1
+        url.put()
+
+    db.run_in_transaction(txn)
+
 def fix_url(url):
     '''Fix url by appending http:// if needed.
 
             long_url = str(url.long)
             memcache.set(short_url, long_url)
 
+        inc_hits(short_url)
         self.redirect(long_url)
 
 app = webapp.WSGIApplication([