Make sure the redis db doesn't grow out of control.
This commit is contained in:
parent
9549d6b0a9
commit
5b0d097f88
@ -106,6 +106,9 @@ class Command(BaseCommand):
|
||||
else:
|
||||
servers_handled.append(data['title'])
|
||||
|
||||
# Keep the amount of data down in redis
|
||||
history.trim_points(server)
|
||||
|
||||
# TODO: do bulk insert instead!
|
||||
server, created = Server.objects.update_or_create(
|
||||
title=data['title'],
|
||||
@ -118,7 +121,6 @@ class Command(BaseCommand):
|
||||
|
||||
# Update the player history
|
||||
history.add_point(server, now, data['player_count'])
|
||||
history.trim_points(server)
|
||||
|
||||
Server.remove_old_servers()
|
||||
|
||||
|
||||
@ -42,8 +42,10 @@ class PlayerHistory(object):
|
||||
self.redis.lpush(server, '{},{}'.format(time, players))
|
||||
|
||||
def trim_points(self, server):
|
||||
'''Trim away too old points in the player history.'''
|
||||
'''Trim away too old points and servers in the player history.'''
|
||||
self.redis.ltrim(server, 0, self.max_points)
|
||||
# let the list expire after a week without updates
|
||||
self.redis.expire(server, 604800)
|
||||
|
||||
def get_points(self, server):
|
||||
'''Get a range of points from the player history.'''
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user