def index(): em = EntityManager() userdata = em.find_one('UserData', {'user_id':bottle.request.session.user_id}) users = [] if userdata: users = em.geospatial_near('UserData', 'location.location', [float(userdata.location.lng), float(userdata.location.lat)], 10000) #regenerate health if userdata.health == 0: userdata.health = 100 em.save('UserData', userdata) userIds = [u.user_id for u in users if str(u.user_id) != str(bottle.request.session.user_id)] users = em.find('User', {'_id':{'$in':userIds}}) bottle.response.viewdata.update({'users':users}) return bottle.template('index.tpl', vd=bottle.response.viewdata)
from models.Models import * import settings import time import memcache MESSAGECACHEKEY = '%s_messages' # usage: MESSAGECACHEKEY % (user_id) CACHEDURATION = (60 * 60) * 24 # 1 day memcache_client = memcache.Client([settings.MEMCACHESERVER]) while True: em = EntityManager() messages = em.find('Message', {'read':False}) object_to_cache = {} message_ids_to_cache= [] user_ids_to_cache = [] for m in messages: message_ids_to_cache.append(str(m._id)) user_ids_to_cache.append(str(m.for_user_id)) if str(m.for_user_id) in object_to_cache: object_to_cache[str(m.for_user_id)].append(m) else: object_to_cache[(m.for_user_id)] = [m] current_cached_message_ids = memcache_client.get('current_cached_message_ids')