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
alpha
physical
Commits
51f12f10
Commit
51f12f10
authored
Apr 16, 2019
by
Kai
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.wanmeizhensuo.com:alpha/physical
parents
ff1f096e
79ecf29a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
11 deletions
+56
-11
collect_data.py
linucb/views/collect_data.py
+0
-1
tag.py
search/views/tag.py
+47
-2
topic.py
search/views/topic.py
+9
-7
tag.py
trans2es/models/tag.py
+0
-1
No files found.
linucb/views/collect_data.py
View file @
51f12f10
...
...
@@ -72,7 +72,6 @@ class CollectData(object):
# Todo:设置过期时间,调研set是否支持
redis_client
.
expire
(
tag_recommend_redis_key
,
7
*
24
*
60
*
60
)
have_read_topic_id_list
=
list
()
have_read_topic_id_list
=
Tools
.
get_have_read_topic_id_list
(
device_id
,
-
1
,
TopicPageType
.
HOME_RECOMMEND
)
promote_recommend_topic_id_list
=
list
()
promote_recommend_topic_id_list
=
TopicHomeRecommend
.
objects
.
using
(
settings
.
SLAVE_DB_NAME
)
.
filter
(
is_online
=
1
)
.
values_list
(
"topic_id"
)
...
...
search/views/tag.py
View file @
51f12f10
...
...
@@ -10,6 +10,8 @@ from search.utils.topic import TopicUtils
from
libs.es
import
ESPerform
from
libs.cache
import
redis_client
from
search.utils.common
import
*
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
import
time
def
get_highlight
(
fields
=
[]):
...
...
@@ -95,9 +97,52 @@ def query_by_tag_type(tag_type_id,offset,size):
@bind
(
"physical/search/choice_push_tag"
)
def
choice_push_tag
(
device_id
,
user_id
):
def
choice_push_tag
(
device_id
,
user_id
):
"""
:remark 挑选push标签
:param device_id:
:param user_id:
:return:
"""
try
:
pass
redis_key_prefix
=
"physical:push_tag:user_id:"
redis_push_tag_key
=
redis_key_prefix
+
str
(
user_id
)
redis_push_tag_data
=
redis_client
.
get
(
redis_push_tag_key
)
redis_push_tag_dict
=
json
.
loads
(
redis_push_tag_data
)
if
redis_push_tag_data
else
{}
now_sec
=
int
(
time
.
time
())
valid_time
=
8
*
7
*
24
*
60
*
60
for
tag_id
in
redis_push_tag_dict
:
if
now_sec
-
redis_push_tag_dict
[
tag_id
]
>=
valid_time
:
redis_push_tag_dict
.
popitem
(
tag_id
)
redis_push_tag_list
=
list
(
redis_push_tag_dict
.
keys
())
account_user_tag_list
=
AccountUserTag
.
objects
.
filter
(
user
=
user_id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
community_tag_follow_list
=
CommunityTagFollow
.
objects
.
filter
(
user_id
=
user_id
)
.
values_list
(
"tag_id"
,
flat
=
True
)
linucb_recommend_redis_prefix
=
"physical:linucb:tag_recommend:device_id:"
tag_recommend_redis_key
=
linucb_recommend_redis_prefix
+
str
(
device_id
)
linucb_recommend_tag_data
=
redis_client
.
get
(
tag_recommend_redis_key
)
linucb_recommend_tag_list
=
json
.
loads
(
linucb_recommend_tag_data
)
if
linucb_recommend_tag_data
else
[]
account_user_tag_list
.
extend
(
community_tag_follow_list
)
account_user_tag_list
.
extend
(
linucb_recommend_tag_list
)
unread_tag_list
=
list
(
set
(
account_user_tag_list
)
-
set
(
redis_push_tag_list
))
ret_tag_set
=
set
()
if
len
(
unread_tag_list
)
>
0
:
for
tag_id
in
unread_tag_list
:
valid_tag_topic_num
=
TopicTag
.
objects
.
filter
(
tag_id
=
tag_id
,
is_online
=
True
)
.
count
()
if
valid_tag_topic_num
>
100
:
ret_tag_set
.
add
(
tag_id
)
redis_push_tag_dict
[
tag_id
]
=
now_sec
if
len
(
ret_tag_set
)
>=
2
:
break
redis_client
.
set
(
redis_push_tag_key
,
json
.
dumps
(
redis_push_tag_dict
))
return
{
"tag_list"
:
list
(
ret_tag_set
)}
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
{
"tag_list"
:
[]}
search/views/topic.py
View file @
51f12f10
...
...
@@ -49,13 +49,15 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
query_type
=
TopicPageType
.
HOME_RECOMMEND
):
try
:
if
query
is
None
:
# redis_key = "physical:home_recommend" + ":user_id:" + str(
# user_id) + ":device_id:" + device_id + ":query_type:" + str(query_type)
redis_key
=
"physical:home_recommend"
+
":device_id:"
+
device_id
+
":query_type:"
+
str
(
query_type
)
if
user_id
>
0
:
redis_key
=
"physical:home_recommend"
+
":user_id:"
+
user_id
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_recommend"
+
":device_id:"
+
device_id
+
":query_type:"
+
str
(
query_type
)
else
:
# redis_key = "physical:home_query" + ":user_id:" + str(
# user_id) + ":device_id:" + device_id + ":query:" + str(query) + ":query_type:" + str(query_type)
redis_key
=
"physical:home_query"
+
":device_id:"
+
device_id
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
if
user_id
>
0
:
redis_key
=
"physical:home_query"
+
":user_id:"
+
user_id
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
else
:
redis_key
=
"physical:home_query"
+
":device_id:"
+
device_id
+
":query:"
+
str
(
query
)
+
":query_type:"
+
str
(
query_type
)
redis_field_list
=
[
b
'have_read_topic_list'
]
...
...
@@ -197,7 +199,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
"have_read_topic_list"
:
json
.
dumps
(
have_read_topic_id_list
),
}
redis_client
.
hmset
(
redis_key
,
redis_dict
)
# 每个session key保存
15分钟
# 每个session key保存
30天
redis_client
.
expire
(
redis_key
,
60
*
60
*
24
*
30
)
return
topic_id_list
...
...
trans2es/models/tag.py
View file @
51f12f10
...
...
@@ -22,7 +22,6 @@ class TopicTag(models.Model):
is_collection
=
models
.
IntegerField
(
verbose_name
=
u"是否编辑标签"
)
class
AccountUserTag
(
models
.
Model
):
class
Meta
:
verbose_name
=
u"用户标签"
...
...
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