Permalink
Browse files

Cleanup counter lib, increase shards, increase cache time

git-svn-id: https://potato.codebasehq.com/getfavicon/getfavicon.svn/trunk@25 0c1c7bd3-9391-4859-b94e-4e2dcdc6a516
  • Loading branch information...
1 parent 5971a81 commit 30bbb24f1eec75ba041b5bc7db267368a739064c jason committed Aug 30, 2010
Showing with 14 additions and 3 deletions.
  1. +1 −1 globals.py
  2. +13 −2 libs/counter/counter.py
View
@@ -5,7 +5,7 @@
err = logging.error
cri = logging.critical
-SHARDS_PER_COUNTER = 100
+SHARDS_PER_COUNTER = 1000
MC_CACHE_TIME = 2419200 #seconds (28 days)
DS_CACHE_TIME = 90 #days
View
@@ -6,24 +6,35 @@
from globals import *
from models import *
+
def ChangeCount(nameOfCounter, delta):
+
shard_id = '/%s/%s' % (nameOfCounter, random.randint(1, SHARDS_PER_COUNTER))
+
def update():
shard = CounterShard.get_by_key_name(shard_id)
if shard:
shard.count += delta
else:
shard = CounterShard(key_name=shard_id, name=nameOfCounter, count=delta)
shard.put()
+
db.run_in_transaction(update)
-
+
+
def GetCount(nameOfCounter):
+
memcache_id = '/CounterShard/%s' % nameOfCounter
result = memcache.get(memcache_id)
+
if not (result == None):
return result
+
result = 0
+
for shard in CounterShard.gql('WHERE name=:1', nameOfCounter):
result += shard.count
- memcache.set(memcache_id, result, 60)
+
+ memcache.set(memcache_id, result, 600)
+
return result

0 comments on commit 30bbb24

Please sign in to comment.