def get_all_topics(topics): users = get_cache_list(People, get_user_id_list(topics), 'hs:people') nodes = get_cache_list(Node, (t.node_id for t in topics), 'hs:node') user_ids = users.keys() node_ids = nodes.keys() for topic in topics: if topic.people_id in user_ids and topic.node_id in node_ids: topic.people = users[topic.people_id] if topic.last_reply_by: topic.last_replyer = users[topic.last_reply_by] else: topic.last_replyer = None topic.node = nodes[topic.node_id] yield topic
def get_full_replies(replies): users = get_cache_list(People, get_replier_id_list(replies), 'hs:people') user_ids = users.keys() for reply in replies: if reply.people_id in user_ids: reply.people = users[reply.people_id] yield reply
def get_full_threads(threads): users = get_cache_list(People, get_user_id_list(threads), 'hs:people') user_ids = users.keys() for thread in threads: if thread.people_id in user_ids: thread.people = users[thread.people_id] yield thread
def run_command(cmd): if cmd == 'createdb': return create_db() if cmd == 'createuser': return create_superuser() if cmd == 'fetchapp': #top paid games app print 'fetchapp' print fetch_rss_app('http://itunes.apple.com/us/rss/toppaidapplications/limit=300/genre=6014/json') if cmd == 'weibo': return test_upload_weibo_pic() if cmd == 'test': from dojang.cache import get_cache_list from account.models import People import cPickle # ps = People.query.all() user_list = dict() data = get_cache_list(People, [], 'people') #res = get_cache_list(People, user_list.keys(), 'people:') for d in data: print "data", d, type(d)
def get_full_topics(topics): users = get_cache_list(People, get_user_id_list(topics), 'hs:people') user_ids = users.keys() for topic in topics: if topic.people_id in user_ids: topic.people = users[topic.people_id] if topic.last_reply_by: topic.last_replyer = users[topic.last_reply_by] else: topic.last_replyer = None yield topic
def run_command(cmd): if cmd == 'createdb': return create_db() if cmd == 'createuser': return create_superuser() if cmd == 'fetchapp': #top paid games app print 'fetchapp' print fetch_rss_app('http://itunes.apple.com/us/rss/toppaidapplications/limit=300/genre=6014/json') if cmd == 'weibo': return test_upload_weibo_pic() if cmd == 'test': from dojang.cache import complex_cache, get_cache_list from account.models import People import cPickle # ps = People.query.all() user_list = dict() # for p in ps: # user_list[p.id] = cPickle.dumps(p) # complex_cache.hmset('people', user_list) # res = complex_cache.hmget('people', user_list.keys()) #id_list = user_list.keys() # id_list = complex_cache.hkeys('people') # data = complex_cache.hmget('people', id_list) # user_list.clear() # data_ids = [] # for d in data: # d = cPickle.loads(d) # user_list[p.id] = p # data_ids.append(str(p.id)) # missing = set(id_list) - set(data_ids) # print "missing",set(id_list),set(data_ids), missing # if missing: # print "set missing" # dct = {} # for item in People.query.filter_by(id__in=missing).all(): # dct[item.id] = item # complex_cache.hmset('people', dct) # data.update(dct) data = get_cache_list(People, [], 'people') #res = get_cache_list(People, user_list.keys(), 'people:') for d in data: print "data", d, type(d)
def get_full_topic(topic): users = get_cache_list(People, get_user_id_list([topic]), 'hs:people') if topic.people_id in users.keys(): topic.people = users[topic.people_id] return topic
def get_full_notifies(messages): users = get_cache_list(People, (m.sender for m in messages), 'member:') for msg in messages: if msg.sender in users: msg.who = users[msg.sender] yield msg