Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
physical
Commits
fb98ca41
Commit
fb98ca41
authored
Dec 13, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
5ebbabdc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
10 deletions
+89
-10
topic.py
search/views/topic.py
+89
-10
No files found.
search/views/topic.py
View file @
fb98ca41
...
...
@@ -35,21 +35,31 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
)
have_read_group_id_tuple
=
set
()
unread_topic_id_list
=
list
()
have_read_topic_id_tuple
=
set
()
have_read_topic_id_set
=
set
()
# 未登录用户已读帖子
unregister_user_have_redis_topic_id_dict
=
dict
()
if
len
(
redis_val_dict
)
>
0
and
offset
>
0
and
offset
==
last_offset_num
:
if
user_id
>
0
:
topic_id_list
=
json
.
loads
(
redis_val_dict
[
b
"unread_topic_id"
])
+
topic_id_list
have_read_topic_id_set
=
set
(
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
]))
else
:
unregister_user_have_redis_topic_id_dict
=
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
])
for
page_id
in
unregister_user_have_redis_topic_id_dict
:
if
int
(
page_id
)
<
offset
:
have_read_topic_id_set
.
union
(
set
(
unregister_user_have_redis_topic_id_dict
[
page_id
]))
if
len
(
redis_val_dict
)
>
0
and
offset
>
0
and
user_id
>
0
and
offset
==
last_offset_num
:
topic_id_list
=
json
.
loads
(
redis_val_dict
[
b
"unread_topic_id"
])
+
topic_id_list
have_read_topic_id_tuple
=
set
(
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
]))
for
item
in
topic_id_list
:
if
item
[
"group_id"
]
in
have_read_group_id_tuple
:
unread_topic_id_list
.
append
(
item
)
else
:
if
item
[
"id"
]
not
in
have_read_topic_id_
tuple
:
if
item
[
"id"
]
not
in
have_read_topic_id_
set
:
recommend_topic_ids
.
append
(
item
[
"id"
])
if
isinstance
(
item
[
"group_id"
],
int
)
and
item
[
"group_id"
]
>
0
:
have_read_group_id_tuple
.
add
(
item
[
"group_id"
])
have_read_topic_id_tuple
.
add
(
item
[
"id"
])
have_read_topic_id_set
.
add
(
item
[
"id"
])
if
len
(
recommend_topic_ids
)
>=
size
:
break
if
len
(
recommend_topic_ids
)
<
size
and
len
(
unread_topic_id_list
)
>
0
:
...
...
@@ -58,10 +68,17 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
recommend_topic_ids
=
recommend_topic_ids
+
offi_unread_topic_id
unread_topic_id_list
=
unread_topic_id_list
[(
size
-
recommend_len
):]
#if len(unread_topic_id_list)>0:
redis_have_redis_data
=
""
if
user_id
>
0
:
redis_have_redis_data
=
json
.
dumps
(
list
(
have_read_topic_id_set
))
else
:
unregister_user_have_redis_topic_id_dict
[
offset
]
=
recommend_topic_ids
redis_have_redis_data
=
json
.
dumps
(
unregister_user_have_redis_topic_id_dict
)
redis_dict
=
{
"unread_topic_id"
:
json
.
dumps
(
unread_topic_id_list
),
"have_read_topic_id"
:
json
.
dumps
(
list
(
have_read_topic_id_tuple
))
,
"have_read_topic_id"
:
redis_have_redis_data
,
"last_offset_num"
:
offset
+
size
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
...
...
@@ -86,6 +103,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
:return:
"""
try
:
"""
if not user_id:
user_id=-1
if not isinstance(session_id,str):
...
...
@@ -122,7 +140,6 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
recommend_topic_ids = recommend_topic_ids + offi_unread_topic_id
unread_topic_id_list = unread_topic_id_list[(size-recommend_len):]
#if len(unread_topic_id_list)>0:
redis_dict = {
"unread_topic_id":json.dumps(unread_topic_id_list),
"have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)),
...
...
@@ -130,8 +147,70 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
}
redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟
redis_client
.
expire
(
redis_key
,
15
*
60
*
60
)
redis_client.expire(redis_key,15*60*60)
"""
if
not
user_id
:
user_id
=-
1
if
not
isinstance
(
session_id
,
str
):
session_id
=
""
redis_key
=
"physical:home_query"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
+
":query:"
+
str
(
query
)
redis_val_dict
=
redis_client
.
hgetall
(
redis_key
)
last_offset_num
=
int
(
redis_val_dict
[
b
"last_offset_num"
])
if
b
"last_offset_num"
in
redis_val_dict
else
-
1
recommend_topic_ids
=
[]
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
,
query
)
have_read_group_id_tuple
=
set
()
unread_topic_id_list
=
list
()
have_read_topic_id_set
=
set
()
# 未登录用户已读帖子
unregister_user_have_redis_topic_id_dict
=
dict
()
if
len
(
redis_val_dict
)
>
0
and
offset
>
0
and
offset
==
last_offset_num
:
if
user_id
>
0
:
topic_id_list
=
json
.
loads
(
redis_val_dict
[
b
"unread_topic_id"
])
+
topic_id_list
have_read_topic_id_set
=
set
(
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
]))
else
:
unregister_user_have_redis_topic_id_dict
=
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
])
for
page_id
in
unregister_user_have_redis_topic_id_dict
:
if
int
(
page_id
)
<
offset
:
have_read_topic_id_set
.
union
(
set
(
unregister_user_have_redis_topic_id_dict
[
page_id
]))
for
item
in
topic_id_list
:
if
item
[
"group_id"
]
in
have_read_group_id_tuple
:
unread_topic_id_list
.
append
(
item
)
else
:
if
item
[
"id"
]
not
in
have_read_topic_id_set
:
recommend_topic_ids
.
append
(
item
[
"id"
])
if
isinstance
(
item
[
"group_id"
],
int
)
and
item
[
"group_id"
]
>
0
:
have_read_group_id_tuple
.
add
(
item
[
"group_id"
])
have_read_topic_id_set
.
add
(
item
[
"id"
])
if
len
(
recommend_topic_ids
)
>=
size
:
break
if
len
(
recommend_topic_ids
)
<
size
and
len
(
unread_topic_id_list
)
>
0
:
recommend_len
=
len
(
recommend_topic_ids
)
offi_unread_topic_id
=
[
item
[
"id"
]
for
item
in
unread_topic_id_list
[:(
size
-
recommend_len
)]]
recommend_topic_ids
=
recommend_topic_ids
+
offi_unread_topic_id
unread_topic_id_list
=
unread_topic_id_list
[(
size
-
recommend_len
):]
redis_have_redis_data
=
""
if
user_id
>
0
:
redis_have_redis_data
=
json
.
dumps
(
list
(
have_read_topic_id_set
))
else
:
unregister_user_have_redis_topic_id_dict
[
offset
]
=
recommend_topic_ids
redis_have_redis_data
=
json
.
dumps
(
unregister_user_have_redis_topic_id_dict
)
redis_dict
=
{
"unread_topic_id"
:
json
.
dumps
(
unread_topic_id_list
),
"have_read_topic_id"
:
redis_have_redis_data
,
"last_offset_num"
:
offset
+
size
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
# 每个session key保存15分钟
redis_client
.
expire
(
redis_key
,
15
*
60
*
60
)
return
{
"recommend_topic_ids"
:
recommend_topic_ids
}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment