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
a4104b5a
Commit
a4104b5a
authored
Dec 13, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
f3602d5c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
26 deletions
+19
-26
topic.py
search/views/topic.py
+19
-26
No files found.
search/views/topic.py
View file @
a4104b5a
...
...
@@ -28,43 +28,42 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
session_id
=
""
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
str
(
user_id
)
+
":session_id:"
+
session_id
redis_field_list
=
[
b
'last_offset_num'
,
b
'unread_topic_id'
,
b
'have_read_topic_id'
]
redis_field_list
=
[
b
'last_offset_num'
,
b
'unread_topic_id'
]
for
page_id
in
range
(
0
,
offset
,
size
):
redis_field_list
.
append
(
str
(
page_id
))
redis_field_val_list
=
redis_client
.
hmget
(
redis_key
,
redis_field_list
)
logging
.
info
(
"duan add,redis_field_list:
%
s,redis_field_val_list:
%
s"
%
(
str
(
redis_field_list
),
str
(
redis_field_val_list
)))
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
#
redis_val_dict = redis_client.hgetall(redis_key)
last_offset_num
=
int
(
redis_
field_val_list
[
0
])
if
redis_field_val_list
[
0
]
else
-
1
recommend_topic_ids
=
[]
topic_id_list
=
TopicUtils
.
get_recommend_topic_ids
(
user_id
,
offset
,
size
*
size
)
have_read_group_id_
tuple
=
set
()
have_read_group_id_
set
=
set
()
unread_topic_id_list
=
list
()
have_read_topic_id_set
=
set
()
# 未登录用户已读帖子
unregister_user_have_redis_topic_id_dict
=
dict
()
ori_unread_topic_id_list
=
list
()
if
len
(
redis_val_dict
)
>
0
and
offset
>
0
:
if
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_set
=
set
(
json
.
loads
(
redis_val_dict
[
b
"have_read_topic_id"
]))
elif
user_id
==-
1
:
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
redis_field_val_list
[
1
]
and
offset
>
0
:
if
(
user_id
>
0
and
offset
==
last_offset_num
)
or
user_id
==-
1
:
ori_unread_topic_id_list
=
json
.
loads
(
redis_field_val_list
[
1
])
topic_id_list
=
ori_unread_topic_id_list
+
topic_id_list
for
have_read_item
in
redis_field_val_list
[
2
:]
:
if
have_read_item
:
have_read_topic_id_set
.
union
(
json
.
loads
(
have_read_item
))
if
user_id
==-
1
:
topic_id_list
=
list
(
set
(
topic_id_list
)
.
difference
(
have_read_topic_id_set
))
for
item
in
topic_id_list
:
if
item
[
"group_id"
]
in
have_read_group_id_
tuple
:
if
item
[
"group_id"
]
in
have_read_group_id_
set
:
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_group_id_
set
.
add
(
item
[
"group_id"
])
have_read_topic_id_set
.
add
(
item
[
"id"
])
if
len
(
recommend_topic_ids
)
>=
size
:
...
...
@@ -76,18 +75,12 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
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
)
if
user_id
==-
1
:
unread_topic_id_list
=
ori_unread_topic_id_list
+
unread_topic_id_list
redis_dict
=
{
"unread_topic_id"
:
json
.
dumps
(
unread_topic_id_list
),
"have_read_topic_id"
:
redis_have_redis_data
,
"last_offset_num"
:
offset
+
size
,
offset
:
recommend_topic_ids
offset
:
json
.
dumps
(
recommend_topic_ids
)
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
# 每个session key保存15分钟
...
...
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