Skip to content

Commit f2d54e1

Browse files
authored
Add warning if poor performance is detected (#145)
1 parent a4059e7 commit f2d54e1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Using the following categories, list your changes in this order:
3434

3535
## [Unreleased]
3636

37-
- Nothing (yet)
37+
### Added
38+
39+
- Added warning if poor system/cache/database performance is detected.
3840

3941
## [3.1.0] - 2023-05-06
4042

src/reactpy_django/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def db_cleanup(immediate: bool = False):
316316
from .config import REACTPY_CACHE, REACTPY_DATABASE, REACTPY_RECONNECT_MAX
317317
from .models import ComponentSession
318318

319+
clean_started_at = datetime.now()
319320
cache_key: str = create_cache_key("last_cleaned")
320321
now_str: str = datetime.strftime(timezone.now(), DATE_FORMAT)
321322
cleaned_at_str: str = caches[REACTPY_CACHE].get(cache_key)
@@ -340,3 +341,12 @@ def db_cleanup(immediate: bool = False):
340341
last_accessed__lte=expires_by
341342
).delete()
342343
caches[REACTPY_CACHE].set(cache_key, now_str, timeout=None)
344+
345+
# Check if cleaning took abnormally long
346+
clean_duration = datetime.now() - clean_started_at
347+
if clean_duration.total_seconds() > 1:
348+
_logger.warning(
349+
"ReactPy has taken %s seconds to clean up expired component sessions. "
350+
"This may indicate a performance issue with your system, cache, or database.",
351+
clean_duration.total_seconds(),
352+
)

src/reactpy_django/websocket/consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def _run_dispatch_loop(self):
7777
carrier=ComponentWebsocket(self.close, self.disconnect, dotted_path),
7878
)
7979
now = timezone.now()
80-
component_args: Sequence[Any] = tuple()
80+
component_args: Sequence[Any] = ()
8181
component_kwargs: MutableMapping[str, Any] = {}
8282

8383
# Verify the component has already been registered

0 commit comments

Comments
 (0)