-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
21 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,13 @@ | ||
from contextvars import ContextVar | ||
from pprint import pprint | ||
|
||
import sentry_sdk | ||
from django.db import connection | ||
|
||
|
||
class DatabaseQueriesMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
pre_query_count = len(connection.queries) | ||
|
||
response = self.get_response(request) | ||
|
||
post_query_count = len(connection.queries) | ||
query_count = post_query_count - pre_query_count | ||
pprint(connection.queries) | ||
print(f"Database queries {query_count}") | ||
|
||
# https://docs.sentry.io/platforms/python/performance/instrumentation/custom-instrumentation/#accessing-the-current-transaction | ||
transaction = sentry_sdk.Hub.current.scope.transaction | ||
|
||
if transaction is not None: | ||
transaction.set_tag("database.query_count", query_count) | ||
|
||
return response | ||
|
||
|
||
_current_financial_year = ContextVar("current_financial_year", default=None) | ||
from core.utils.generic_helpers import get_current_financial_year | ||
|
||
|
||
class CoreRequestDataMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
request.current_financial_year = get_current_financial_year() | ||
|
||
response = self.get_response(request) | ||
|
||
_current_financial_year.set(None) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters