Skip to content

Commit aadefbc

Browse files
committed
Add django-debug-toolbar + fix slow SQL qieries
1 parent 5651475 commit aadefbc

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

boards/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from django.contrib.humanize.templatetags.humanize import naturaltime
55
from django.db import models
6-
from django.contrib.postgres.fields import JSONField
6+
from django.db.models import JSONField
77
from slugify import slugify
88

99
from boards.icons import DOMAIN_ICONS, DOMAIN_FAVICONS

boards/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def board(request, board_slug):
2828
return cached_page
2929

3030
blocks = BoardBlock.objects.filter(board=board)
31-
feeds = BoardFeed.objects.filter(board=board)
31+
feeds = BoardFeed.objects.select_related("articles").filter(board=board)
3232
result = render(request, "board.html", {
3333
"board": board,
3434
"blocks": blocks,

infomate/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
DEBUG = (os.getenv("DEBUG") != "false") # SECURITY WARNING: don't run with debug turned on in production!
1111
SECRET_KEY = os.getenv("SECRET_KEY") or "wow so secret"
1212
ALLOWED_HOSTS = ["127.0.0.1", "localhost", "0.0.0.0", "infomate.club"]
13+
INTERNAL_IPS = ["127.0.0.1"]
1314

1415
INSTALLED_APPS = [
1516
"django.contrib.staticfiles",
1617
"django.contrib.humanize",
1718
"django_bleach",
1819
"boards",
19-
"parsing"
20+
"parsing",
2021
]
2122

2223
MIDDLEWARE = [
@@ -123,3 +124,7 @@
123124
dsn=SENTRY_DSN,
124125
integrations=[DjangoIntegration()]
125126
)
127+
128+
if DEBUG:
129+
INSTALLED_APPS += ["debug_toolbar"]
130+
MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware"] + MIDDLEWARE

infomate/urls.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from django.urls import path
1+
from django.conf import settings
2+
from django.urls import path, include
23
from django.views.decorators.cache import cache_page
34

45
from boards.views import index, board, privacy_policy, what
5-
from infomate import settings
66
from parsing.views import TelegramChannelFeed
77

88
urlpatterns = [
@@ -16,5 +16,12 @@
1616
path("parsing/telegram/<str:channel_name>/",
1717
cache_page(settings.TELEGRAM_CACHE_SECONDS)(TelegramChannelFeed()),
1818
name="telegram_channel_feed"),
19-
2019
]
20+
21+
if settings.DEBUG:
22+
import debug_toolbar
23+
urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns
24+
25+
DEBUG_TOOLBAR_CONFIG = {
26+
"SHOW_TOOLBAR_CALLBACK": lambda request: True,
27+
}

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Django==3.2.12
1+
Django==4.0.4
22
gunicorn==20.1.0
33
uvicorn==0.17.6
44
psycopg2-binary==2.9.3
@@ -13,3 +13,5 @@ sentry-sdk==1.5.8
1313
nltk==3.6.6
1414
newspaper3k>=0.2.8
1515
django-bleach==1.0.0
16+
django-debug-toolbar==3.4.0
17+

templates/common/favicon.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load staticfiles %}
1+
{% load static %}
22
<link rel="icon" type="image/png" href="{% static "images/favicon/favicon-16x16.png" %}" sizes="16x16">
33
<link rel="icon" type="image/png" href="{% static "images/favicon/favicon-32x32.png" %}" sizes="32x32">
44
<link rel="icon" type="image/png" href="{% static "images/favicon/android-chrome-192x192.png" %}" sizes="192x192">

0 commit comments

Comments
 (0)