Add Silk middleware and related settings for performance monitoring
- Introduced SILK_ENABLED setting to toggle Silk middleware. - Updated ALLOWED_HOSTS to include "testserver" when not in DEBUG mode. - Modified urlpatterns to conditionally include Silk URLs. - Added django-silk dependency to pyproject.toml. - Enhanced feed queries to optimize performance and reduce N+1 issues. - Updated tests to verify query limits for various feeds.
This commit is contained in:
parent
2f9c5a9328
commit
e968f5cdea
9 changed files with 289 additions and 57 deletions
|
|
@ -39,6 +39,7 @@ def env_int(key: str, default: int) -> int:
|
|||
|
||||
|
||||
DEBUG: bool = env_bool(key="DEBUG", default=True)
|
||||
RUNNING_TESTS: bool = "PYTEST_VERSION" in os.environ or any("pytest" in arg for arg in sys.argv)
|
||||
|
||||
|
||||
def get_data_dir() -> Path:
|
||||
|
|
@ -110,7 +111,7 @@ INTERNAL_IPS: list[str] = []
|
|||
if DEBUG:
|
||||
INTERNAL_IPS = ["127.0.0.1", "localhost"] # pyright: ignore[reportConstantRedefinition]
|
||||
|
||||
ALLOWED_HOSTS: list[str] = [".localhost", "127.0.0.1", "[::1]"]
|
||||
ALLOWED_HOSTS: list[str] = [".localhost", "127.0.0.1", "[::1]", "testserver"]
|
||||
if not DEBUG:
|
||||
ALLOWED_HOSTS = ["ttvdrops.lovinator.space"] # pyright: ignore[reportConstantRedefinition]
|
||||
|
||||
|
|
@ -141,10 +142,12 @@ INSTALLED_APPS: list[str] = [
|
|||
"django.contrib.contenttypes",
|
||||
"django.contrib.staticfiles",
|
||||
"twitch.apps.TwitchConfig",
|
||||
*(["silk"] if not RUNNING_TESTS else []),
|
||||
]
|
||||
|
||||
MIDDLEWARE: list[str] = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
*(["silk.middleware.SilkyMiddleware"] if not RUNNING_TESTS else []),
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ def test_allowed_hosts_when_debug_true(reload_settings_module: Callable[..., Mod
|
|||
reloaded: ModuleType = reload_settings_module(DEBUG="1")
|
||||
|
||||
assert reloaded.DEBUG is True
|
||||
assert reloaded.ALLOWED_HOSTS == [".localhost", "127.0.0.1", "[::1]"]
|
||||
assert reloaded.ALLOWED_HOSTS == [".localhost", "127.0.0.1", "[::1]", "testserver"]
|
||||
|
||||
|
||||
def test_debug_defaults_true_when_missing(reload_settings_module: Callable[..., ModuleType]) -> None:
|
||||
|
|
|
|||
|
|
@ -11,10 +11,13 @@ if TYPE_CHECKING:
|
|||
from django.urls.resolvers import URLPattern
|
||||
from django.urls.resolvers import URLResolver
|
||||
|
||||
urlpatterns: list[URLResolver] | list[URLPattern | URLResolver] = [ # type: ignore[assignment]
|
||||
urlpatterns: [URLPattern | URLResolver] = [ # type: ignore[assignment]
|
||||
path(route="", view=include("twitch.urls", namespace="twitch")),
|
||||
]
|
||||
|
||||
if getattr(settings, "ENABLE_SILK", False):
|
||||
urlpatterns += [path("silk/", include("silk.urls", namespace="silk"))]
|
||||
|
||||
# Serve media in development
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue