Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
b4621d05
Commit
b4621d05
authored
12 years ago
by
Mike Chen
Browse files
Options
Downloads
Patches
Plain Diff
added QueryCountDebugMiddleware
parent
7c22a39a
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/django_comment_client/utils.py
+27
-1
27 additions, 1 deletion
lms/djangoapps/django_comment_client/utils.py
lms/envs/common.py
+1
-0
1 addition, 0 deletions
lms/envs/common.py
with
28 additions
and
1 deletion
lms/djangoapps/django_comment_client/utils.py
+
27
−
1
View file @
b4621d05
...
...
@@ -5,7 +5,8 @@ from xmodule.modulestore import Location
from
xmodule.modulestore.django
import
modulestore
from
django.http
import
HttpResponse
from
django.utils
import
simplejson
from
django.db
import
connection
import
logging
from
django.conf
import
settings
import
operator
import
itertools
...
...
@@ -128,6 +129,31 @@ class ViewNameMiddleware(object):
def
process_view
(
self
,
request
,
view_func
,
view_args
,
view_kwargs
):
request
.
view_name
=
view_func
.
__name__
class
QueryCountDebugMiddleware
(
object
):
"""
This middleware will log the number of queries run
and the total time taken for each request (with a
status code of 200). It does not currently support
multi-db setups.
"""
def
process_response
(
self
,
request
,
response
):
if
response
.
status_code
==
200
:
total_time
=
0
for
query
in
connection
.
queries
:
query_time
=
query
.
get
(
'
time
'
)
if
query_time
is
None
:
# django-debug-toolbar monkeypatches the connection
# cursor wrapper and adds extra information in each
# item in connection.queries. The query time is stored
# under the key "duration" rather than "time" and is
# in milliseconds, not seconds.
query_time
=
query
.
get
(
'
duration
'
,
0
)
/
1000
total_time
+=
float
(
query_time
)
logging
.
info
(
'
%s queries run, total %s seconds
'
%
(
len
(
connection
.
queries
),
total_time
))
return
response
def
get_annotated_content_info
(
course_id
,
content
,
user
,
type
):
return
{
'
editable
'
:
check_permissions_by_view
(
user
,
course_id
,
content
,
"
update_thread
"
if
type
==
'
thread
'
else
"
update_comment
"
),
...
...
This diff is collapsed.
Click to expand it.
lms/envs/common.py
+
1
−
0
View file @
b4621d05
...
...
@@ -329,6 +329,7 @@ MIDDLEWARE_CLASSES = (
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
'
django_comment_client.utils.ViewNameMiddleware
'
,
'
django_comment_client.utils.QueryCountDebugMiddleware
'
,
)
############################### Pipeline #######################################
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment