From 94b17ee88b57261669ff4bdfcd32ca8fd411e494 Mon Sep 17 00:00:00 2001 From: Matthew Curran Date: Mon, 31 Aug 2026 11:59:16 -0400 Subject: [PATCH 1/4] gwy: Memory profiler on file upload create function. --- .../api_methods/utils/profilers.py | 22 +++++++++++++++++++ .../api_methods/views/file_endpoints.py | 2 ++ 2 files changed, 24 insertions(+) create mode 100644 gateway/sds_gateway/api_methods/utils/profilers.py diff --git a/gateway/sds_gateway/api_methods/utils/profilers.py b/gateway/sds_gateway/api_methods/utils/profilers.py new file mode 100644 index 00000000..0d4e45d1 --- /dev/null +++ b/gateway/sds_gateway/api_methods/utils/profilers.py @@ -0,0 +1,22 @@ +"""Profiler wrappers to check resource usage.""" + +import functools +import tracemalloc + +from loguru import logger + + +def profile_memory(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + tracemalloc.start() + result = func(*args, **kwargs) + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + logger.info( + f"[Memory Profiler] {func.__name__} Current: {current / 10**6:.2f} MB" + ) + logger.info(f"[Memory Profiler] {func.__name__} Peak: {peak / 10**6:.2f} MB") + return result + + return wrapper diff --git a/gateway/sds_gateway/api_methods/views/file_endpoints.py b/gateway/sds_gateway/api_methods/views/file_endpoints.py index 6b5444af..545f1e10 100644 --- a/gateway/sds_gateway/api_methods/views/file_endpoints.py +++ b/gateway/sds_gateway/api_methods/views/file_endpoints.py @@ -46,6 +46,7 @@ get_accessible_files_queryset, ) from sds_gateway.api_methods.utils.asset_access_control import user_has_access_to_file +from sds_gateway.api_methods.utils.profilers import profile_memory from sds_gateway.api_methods.utils.relationship_utils import ( detach_item_from_all_datasets, ) @@ -99,6 +100,7 @@ def _paginated_list_response( ], summary="Upload File", ) + @profile_memory def create(self, request: Request) -> Response: """Uploads a file to the server.""" From 9d915ff187b55263c6e6465dc886d4a041173e94 Mon Sep 17 00:00:00 2001 From: Matthew Curran Date: Mon, 31 Aug 2026 13:41:52 -0400 Subject: [PATCH 2/4] gwy: Change sign-in url based on SOCIALACCOUNT_ONLY setting. --- gateway/sds_gateway/templates/base.html | 8 +++++++- .../templates/socialaccount/snippets/login.html | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gateway/sds_gateway/templates/base.html b/gateway/sds_gateway/templates/base.html index b85243df..81fa738f 100644 --- a/gateway/sds_gateway/templates/base.html +++ b/gateway/sds_gateway/templates/base.html @@ -186,7 +186,13 @@ {% else %} {% endif %} diff --git a/gateway/sds_gateway/templates/socialaccount/snippets/login.html b/gateway/sds_gateway/templates/socialaccount/snippets/login.html index 546beeb9..2239a399 100644 --- a/gateway/sds_gateway/templates/socialaccount/snippets/login.html +++ b/gateway/sds_gateway/templates/socialaccount/snippets/login.html @@ -6,7 +6,7 @@ {% if socialaccount_providers %} {% if not SOCIALACCOUNT_ONLY %} {% element h2 %} - {% translate "Or use a third-party" %} + {% translate "Or use a third-party ID provider" %} {% endelement %} {% endif %} {% include "socialaccount/snippets/provider_list.html" with process="login" %} From 07ac0d79dbe1c1a9de46e6acaaadf619a850dc75 Mon Sep 17 00:00:00 2001 From: Matthew Curran Date: Mon, 31 Aug 2026 14:10:23 -0400 Subject: [PATCH 3/4] gwy: Improved formatting around Auth0 log-in button. --- gateway/sds_gateway/static/css/components.css | 28 +++++++++++++++++++ .../templates/allauth/elements/provider.html | 8 +++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/gateway/sds_gateway/static/css/components.css b/gateway/sds_gateway/static/css/components.css index 973aa8ca..7680a213 100644 --- a/gateway/sds_gateway/static/css/components.css +++ b/gateway/sds_gateway/static/css/components.css @@ -378,6 +378,34 @@ textarea.form-control-plaintext { margin-bottom: 1rem; } +.provider-list { + display: grid; + gap: 0.75rem; + width: min(100%, 22rem); + margin: 0; + padding: 0; + list-style: none; +} + +.hero-content .provider-list .social-provider-button { + display: flex; + align-items: center; + justify-content: center; + gap: 0.5rem; + width: 100%; + min-height: 44px; + color: var(--bs-white); + font-weight: 500; + text-decoration: none; +} + +.hero-content .provider-list .social-provider-button:hover, +.hero-content .provider-list .social-provider-button:focus, +.hero-content .provider-list .social-provider-button:active { + color: var(--bs-white); + text-decoration: none; +} + /* Custom Table */ .custom-table { width: 100%; diff --git a/gateway/sds_gateway/templates/allauth/elements/provider.html b/gateway/sds_gateway/templates/allauth/elements/provider.html index fc53724e..c0c4550e 100644 --- a/gateway/sds_gateway/templates/allauth/elements/provider.html +++ b/gateway/sds_gateway/templates/allauth/elements/provider.html @@ -1,8 +1,8 @@
  • - - {{ attrs.name }} + title="Sign in with {{ attrs.name }}" + class="btn btn-primary social-provider-button"> + + Continue with {{ attrs.name }}
  • From 502bdbd8cc0d30c3081cf8a586d9d7888866acde Mon Sep 17 00:00:00 2001 From: Matthew Curran Date: Mon, 31 Aug 2026 14:56:51 -0400 Subject: [PATCH 4/4] gwy: Fix potential crashes in profile_memory annotation. Remove the annotation from create function for prod. --- .../api_methods/utils/profilers.py | 41 ++++++++++++++----- .../api_methods/views/file_endpoints.py | 2 - 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/gateway/sds_gateway/api_methods/utils/profilers.py b/gateway/sds_gateway/api_methods/utils/profilers.py index 0d4e45d1..f6bb90ec 100644 --- a/gateway/sds_gateway/api_methods/utils/profilers.py +++ b/gateway/sds_gateway/api_methods/utils/profilers.py @@ -1,22 +1,43 @@ -"""Profiler wrappers to check resource usage.""" +"""Profiler wrappers to check resource usage. +To use, import the decorator as such: +from sds_gateway.api_methods.utils.profilers import profile_memory +Then annotate functions to profile with @profile_memory""" import functools +import threading import tracemalloc from loguru import logger +_tracemalloc_lock = threading.Lock() + def profile_memory(func): @functools.wraps(func) def wrapper(*args, **kwargs): - tracemalloc.start() - result = func(*args, **kwargs) - current, peak = tracemalloc.get_traced_memory() - tracemalloc.stop() - logger.info( - f"[Memory Profiler] {func.__name__} Current: {current / 10**6:.2f} MB" - ) - logger.info(f"[Memory Profiler] {func.__name__} Peak: {peak / 10**6:.2f} MB") - return result + with _tracemalloc_lock: + owns_tracing = not tracemalloc.is_tracing() + + if owns_tracing: + tracemalloc.start() + + try: + return func(*args, **kwargs) + finally: + current, peak = tracemalloc.get_traced_memory() + + if owns_tracing and tracemalloc.is_tracing(): + tracemalloc.stop() + + logger.info( + "[Memory Profiler] {} Current: {:.2f} MB", + func.__name__, + current / 10**6, + ) + logger.info( + "[Memory Profiler] {} Peak: {:.2f} MB", + func.__name__, + peak / 10**6, + ) return wrapper diff --git a/gateway/sds_gateway/api_methods/views/file_endpoints.py b/gateway/sds_gateway/api_methods/views/file_endpoints.py index 545f1e10..6b5444af 100644 --- a/gateway/sds_gateway/api_methods/views/file_endpoints.py +++ b/gateway/sds_gateway/api_methods/views/file_endpoints.py @@ -46,7 +46,6 @@ get_accessible_files_queryset, ) from sds_gateway.api_methods.utils.asset_access_control import user_has_access_to_file -from sds_gateway.api_methods.utils.profilers import profile_memory from sds_gateway.api_methods.utils.relationship_utils import ( detach_item_from_all_datasets, ) @@ -100,7 +99,6 @@ def _paginated_list_response( ], summary="Upload File", ) - @profile_memory def create(self, request: Request) -> Response: """Uploads a file to the server."""