Commit 428e2b15 authored by 段英荣's avatar 段英荣

filter have read topic id list

parent 19d7cb40
......@@ -59,12 +59,12 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
redis_field_val_list = redis_client.hmget(redis_key,redis_field_list)
recommend_topic_ids = []
have_read_topic_id_set = set()
have_read_topic_id_list = list()
if redis_field_val_list[0]:
have_read_topic_id_set = set(json.loads(redis_field_val_list[0]))
have_read_topic_id_list = list(json.loads(redis_field_val_list[0]))
topic_id_dict = TopicUtils.get_recommend_topic_ids(user_id, offset, size*size,query,query_type=query_type,filter_topic_id_list=have_read_topic_id_set)
topic_id_dict = TopicUtils.get_recommend_topic_ids(user_id, offset, size*size,query,query_type=TopicPageType.FIND_PAGE,filter_topic_id_list=have_read_topic_id_set)
have_read_group_id_set = set()
have_read_user_id_set = set()
unread_topic_id_dict = dict()
......@@ -81,13 +81,14 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
if isinstance(topic_id_dict[topic_id][0],int) and topic_id_dict[topic_id][0]>0 and cur_page_group_num<(size*0.9):
have_read_group_id_set.add(topic_id_dict[topic_id][0])
have_read_user_id_set.add(topic_id_dict[topic_id][1])
have_read_topic_id_set.add(topic_id)
have_read_topic_id_list.append(topic_id)
cur_page_group_num += 1
recommend_topic_ids.append(topic_id)
elif topic_id_dict[topic_id] and cur_page_user_num<(size*0.1):
have_read_user_id_set.add(topic_id_dict[topic_id][1])
cur_page_user_num += 1
recommend_topic_ids.append(topic_id)
have_read_topic_id_list.append(topic_id)
else:
unread_topic_id_dict[topic_id] = topic_id_dict[topic_id]
......@@ -99,11 +100,15 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
for unread_topic_id in unread_topic_id_dict:
if len(recommend_topic_ids)<size:
recommend_topic_ids.append(unread_topic_id)
have_read_user_id_set.add(unread_topic_id)
have_read_topic_id_list.append(unread_topic_id)
else:
break
if len(have_read_topic_id_list) > 10000:
cut_len = len(have_read_topic_id_list)-10000
have_read_topic_id_list = have_read_topic_id_list[cut_len:]
redis_dict = {
"have_read_topic_list":json.dumps(list(have_read_user_id_set)),
"have_read_topic_list":json.dumps(have_read_topic_id_list),
}
redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment