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
b0eae044
Commit
b0eae044
authored
Sep 23, 2019
by
高雅喆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加数据库丢失连接保护
parent
a14b8824
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
tools.py
libs/tools.py
+10
-0
tag.py
search/views/tag.py
+7
-6
No files found.
libs/tools.py
View file @
b0eae044
...
...
@@ -8,6 +8,7 @@ import traceback
from
libs.cache
import
redis_client
import
json
import
logging
from
django.db
import
connection
def
tzlc
(
dt
,
truncate_to_sec
=
True
):
...
...
@@ -58,3 +59,12 @@ def get_have_read_lin_pictorial_id_list(device_id,user_id,query_type):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
list
()
def
is_connection_usable
():
"""判断当前mysql的链接是否正常,不正常就close掉"""
try
:
connection
.
connection
.
ping
()
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
search/views/tag.py
View file @
b0eae044
...
...
@@ -11,9 +11,11 @@ from libs.cache import redis_client
from
search.utils.common
import
*
from
trans2es.models.tag
import
TopicTag
,
AccountUserTag
,
CommunityTagFollow
,
Tag
import
time
from
libs.tools
import
is_connection_usable
from
trans2es.models.tag
import
CommunityTagSetRelation
from
django.conf
import
settings
from
libs.error
import
logging_exception
from
django.db
import
connection
def
get_highlight
(
fields
=
[]):
...
...
@@ -235,14 +237,15 @@ def get_same_tagset_ids(tag_list):
:param tag_list:
:return:
"""
try
:
all_tag
=
list
()
if
isinstance
(
tag_list
,
int
):
all_tag
.
append
(
tag_list
)
else
:
all_tag
=
tag_list
try
:
if
not
is_connection_usable
():
connection
.
close
()
logging
.
error
(
"unable mysql connection and close"
)
tag_set_list_id
=
list
(
CommunityTagSetRelation
.
objects
.
filter
(
tag_id__in
=
all_tag
,
is_deleted
=
False
)
.
values_list
(
"tag_set_id"
,
flat
=
True
))
...
...
@@ -250,12 +253,10 @@ def get_same_tagset_ids(tag_list):
CommunityTagSetRelation
.
objects
.
filter
(
tag_set_id__in
=
tag_set_list_id
,
is_deleted
=
False
)
.
values_list
(
"tag_id"
,
flat
=
True
))
all_tag
.
extend
(
tag_ids
)
logging
.
info
(
"get_same_tagset_ids:
%
s"
%
str
(
all_tag
))
return
list
(
set
(
all_tag
))
except
:
logging_exception
()
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
all_tag
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