Skip to content

Django Session Cleanup (save 5 gb) #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged

Django Session Cleanup (save 5 gb) #1121

merged 3 commits into from
May 6, 2025

Conversation

Jay-Lalwani
Copy link
Collaborator

@Jay-Lalwani Jay-Lalwani commented May 6, 2025

django clearsessions command

image

Summary by CodeRabbit

  • Chores
    • Removed support for social authentication, including related dependencies, URL routes, context processors, authentication pipeline, and templates.
  • Bug Fixes
    • Expired sessions are now cleared automatically during container startup, improving session management.

Copy link

coderabbitai bot commented May 6, 2025

Walkthrough

This update removes all code, dependencies, templates, and settings related to social authentication using the social-auth-app-django package. It deletes custom authentication pipeline logic, associated views, forms, context processors, URL patterns, and the relevant dependency. The container startup script is updated to clear expired Django sessions.

Changes

File(s) Change Summary
requirements.txt Removed the social-auth-app-django dependency.
scripts/container-startup.sh Added python manage.py clearsessions after cache invalidation in the startup sequence.
tcf_core/auth_pipeline.py Deleted the entire file containing custom social authentication pipeline functions.
tcf_core/settings/base.py Removed social_django context processors from the Django TEMPLATES configuration.
tcf_core/urls.py Removed the inclusion of social_django URL patterns for the "oauth/" path.
tcf_website/templates/login/extra_info_form.html Deleted the HTML template used for collecting extra user information during registration.
tcf_website/views/init.py Removed imports of collect_extra_info, login_error, and password_error from the auth module.
tcf_website/views/auth.py Deleted error views, the extra user info form, and the view for collecting extra user information.

Sequence Diagram(s)

sequenceDiagram
    participant Container
    participant Django

    Container->>Django: python manage.py invalidate_cachalot
    Container->>Django: python manage.py clearsessions
Loading

Poem

A hop and a skip, away goes the old,
Social login stories, now left untold.
Pip’s list is lighter, the URLs are neat,
No more extra forms for users to greet.
With sessions now cleared, the app’s feeling spry—
A rabbit’s quick update, waving goodbye! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
tcf_website/views/__init__.py (1)

7-7: Consider declaring __all__ for explicit exports
As this module aggregates and re-exports view functions, adding an explicit __all__ list (e.g., __all__ = ["ads", "login", "logout", ...]) will make the public API clearer and suppress any F401 lint warnings.

🧰 Tools
🪛 Ruff (0.8.2)

7-7: .auth.login imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .auth.logout imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

scripts/container-startup.sh (2)

14-15: Improve logging around session cleanup

Right now the clearsessions call runs silently. Adding simple echo statements before and after will make it easier to debug startup issues and verify that expired sessions were cleared successfully.

Proposed diff:

- python manage.py clearsessions
+ echo 'Running Django clearsessions to remove expired sessions...'
+ python manage.py clearsessions
+ echo 'Django clearsessions completed'

14-15: Consider restricting session cleanup to production

Clearing sessions on every container start can be problematic in development or staging environments (it might remove in-use sessions). You could guard this command with an environment check:

- echo 'Running Django clearsessions to remove expired sessions...'
- python manage.py clearsessions
- echo 'Django clearsessions completed'
+ if [ "$DJANGO_ENV" = "production" ]; then
+   echo 'Running Django clearsessions to remove expired sessions...'
+   python manage.py clearsessions
+   echo 'Django clearsessions completed'
+ else
+   echo 'Skipping clearsessions (non-production environment)'
+ fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dab578f and 70c8fc2.

📒 Files selected for processing (8)
  • requirements.txt (0 hunks)
  • scripts/container-startup.sh (1 hunks)
  • tcf_core/auth_pipeline.py (0 hunks)
  • tcf_core/settings/base.py (0 hunks)
  • tcf_core/urls.py (0 hunks)
  • tcf_website/templates/login/extra_info_form.html (0 hunks)
  • tcf_website/views/__init__.py (1 hunks)
  • tcf_website/views/auth.py (0 hunks)
💤 Files with no reviewable changes (6)
  • requirements.txt
  • tcf_core/settings/base.py
  • tcf_website/templates/login/extra_info_form.html
  • tcf_website/views/auth.py
  • tcf_core/urls.py
  • tcf_core/auth_pipeline.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
tcf_website/views/__init__.py (1)
tcf_website/views/auth.py (2)
  • login (19-36)
  • logout (106-120)
🪛 Ruff (0.8.2)
tcf_website/views/__init__.py

7-7: .auth.login imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .auth.logout imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: django
  • GitHub Check: pylint
🔇 Additional comments (1)
tcf_website/views/__init__.py (1)

7-7:

✅ Verification successful

Removed deprecated social-auth view imports
The import of only login and logout correctly reflects the removal of collect_extra_info, login_error, and password_error, aligning with the broader cleanup of custom social authentication logic. Verify that no URL patterns or templates still reference the deleted views.

Run the following to ensure no stray references remain:


🏁 Script executed:

#!/bin/bash
# Verify removal of deprecated view imports
rg -n 'collect_extra_info|login_error|password_error'

Length of output: 55


Confirmed removal of deprecated social-auth view imports
Importing only login and logout in tcf_website/views/__init__.py correctly reflects the removal of collect_extra_info, login_error, and password_error. A repository-wide search found no remaining references in URL patterns, templates, or other code.

  • File affected: tcf_website/views/init.py (line 7)
  • No occurrences of collect_extra_info, login_error, or password_error in the codebase
🧰 Tools
🪛 Ruff (0.8.2)

7-7: .auth.login imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


7-7: .auth.logout imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

@Jay-Lalwani Jay-Lalwani merged commit 060e12e into dev May 6, 2025
4 checks passed
@Jay-Lalwani Jay-Lalwani deleted the cleanup branch May 6, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant