Skip to content

Commit 43ddd83

Browse files
authored
Merge pull request #56 from mfwolffe/backend-remodel-phase1
Backend query remodel: Phase 1 (N+1 + write explosion) + Phase 2 (CourseAssignment)
2 parents b198cea + 0c8e28b commit 43ddd83

70 files changed

Lines changed: 3872 additions & 738 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/api_router.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848

4949
assignments_router = nested_cls(courses_router, "assignments", lookup="assignment")
5050
assignments_router.register("submissions", SubmissionViewSet)
51-
assignments_router.register("activity-progress", ActivityProgressViewSet, basename="activity-progress")
51+
assignments_router.register(
52+
"activity-progress", ActivityProgressViewSet, basename="activity-progress"
53+
)
5254

5355
attachments_router = nested_cls(assignments_router, "submissions", lookup="submission")
5456
attachments_router.register("attachments", AttachmentViewSet)

config/settings/railway.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
# Allow Railway's domain and custom domains
1818
ALLOWED_HOSTS = env.list(
19-
"DJANGO_ALLOWED_HOSTS",
20-
default=["localhost", ".railway.app", ".up.railway.app"]
19+
"DJANGO_ALLOWED_HOSTS", default=["localhost", ".railway.app", ".up.railway.app"]
2120
)
2221

2322
# DATABASES
@@ -62,7 +61,9 @@
6261
# STATIC FILES (whitenoise)
6362
# ------------------------------------------------------------------------------
6463
INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS # noqa F405
65-
MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware") # After SecurityMiddleware
64+
MIDDLEWARE.insert(
65+
1, "whitenoise.middleware.WhiteNoiseMiddleware"
66+
) # After SecurityMiddleware
6667

6768
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
6869
STATIC_URL = "/static/"
@@ -79,12 +80,10 @@
7980
# ------------------------------------------------------------------------------
8081
# Use console backend for development/testing (emails print to console)
8182
EMAIL_BACKEND = env(
82-
"DJANGO_EMAIL_BACKEND",
83-
default="django.core.mail.backends.console.EmailBackend"
83+
"DJANGO_EMAIL_BACKEND", default="django.core.mail.backends.console.EmailBackend"
8484
)
8585
DEFAULT_FROM_EMAIL = env(
86-
"DJANGO_DEFAULT_FROM_EMAIL",
87-
default="MusicCPR <noreply@musiccpr.org>"
86+
"DJANGO_DEFAULT_FROM_EMAIL", default="MusicCPR <noreply@musiccpr.org>"
8887
)
8988

9089
# ADMIN
@@ -97,9 +96,7 @@
9796
"version": 1,
9897
"disable_existing_loggers": False,
9998
"formatters": {
100-
"verbose": {
101-
"format": "%(levelname)s %(asctime)s %(name)s %(message)s"
102-
}
99+
"verbose": {"format": "%(levelname)s %(asctime)s %(name)s %(message)s"}
103100
},
104101
"handlers": {
105102
"console": {
@@ -133,17 +130,13 @@
133130
r"^https://.*\.railway\.app$",
134131
r"^http://localhost:\d+$",
135132
r"^http://127\.0\.0\.1:\d+$",
136-
]
133+
],
137134
)
138135

139136
# Also allow specific origins if set
140-
CORS_ALLOWED_ORIGINS = env.list(
141-
"CORS_ALLOWED_ORIGINS",
142-
default=[]
143-
)
137+
CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS", default=[])
144138

145139
# CSRF trusted origins (needed for admin)
146140
CSRF_TRUSTED_ORIGINS = env.list(
147-
"CSRF_TRUSTED_ORIGINS",
148-
default=["https://*.railway.app", "https://*.vercel.app"]
141+
"CSRF_TRUSTED_ORIGINS", default=["https://*.railway.app", "https://*.vercel.app"]
149142
)

config/urls.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
def debug_media(request):
1616
"""Diagnostic endpoint to check media files."""
1717
import subprocess
18+
1819
result = {
1920
"MEDIA_ROOT": str(settings.MEDIA_ROOT),
2021
"MEDIA_ROOT_exists": os.path.exists(settings.MEDIA_ROOT),
@@ -29,7 +30,9 @@ def debug_media(request):
2930
for f in filenames[:20]: # Limit to first 20
3031
files.append(os.path.join(root, f).replace(settings.MEDIA_ROOT, ""))
3132
result["files"] = files
32-
result["file_count"] = sum(len(f) for _, _, f in os.walk(settings.MEDIA_ROOT))
33+
result["file_count"] = sum(
34+
len(f) for _, _, f in os.walk(settings.MEDIA_ROOT)
35+
)
3336
except Exception as e:
3437
result["error"] = str(e)
3538
else:
@@ -39,10 +42,13 @@ def debug_media(request):
3942
teleband_media = os.path.join(os.getcwd(), "teleband", "media")
4043
result["teleband_media_exists"] = os.path.exists(teleband_media)
4144
if os.path.exists(teleband_media):
42-
result["teleband_media_count"] = sum(len(f) for _, _, f in os.walk(teleband_media))
45+
result["teleband_media_count"] = sum(
46+
len(f) for _, _, f in os.walk(teleband_media)
47+
)
4348

4449
return JsonResponse(result)
4550

51+
4652
urlpatterns = [
4753
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
4854
path("debug-media/", debug_media, name="debug-media"),
@@ -68,9 +74,11 @@ def debug_media(request):
6874
# Serve media files - in production with S3 this is handled by S3,
6975
# but for Railway/local deployments we serve from filesystem
7076
# Note: static() only works with DEBUG=True, so we use serve() directly for non-S3 deployments
71-
if not hasattr(settings, 'DEFAULT_FILE_STORAGE') or 'S3' not in getattr(settings, 'DEFAULT_FILE_STORAGE', ''):
77+
if not hasattr(settings, "DEFAULT_FILE_STORAGE") or "S3" not in getattr(
78+
settings, "DEFAULT_FILE_STORAGE", ""
79+
):
7280
urlpatterns += [
73-
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
81+
re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT}),
7482
]
7583

7684
if settings.DEBUG:

0 commit comments

Comments
 (0)