#3119·casdoor

[feature] Optimize Session Handling to Avoid Redundant Session Creation

Author: hamidrabediCreated Aug 12, 2024Updated Mar 4, 2026
Labelsenhancement

The current implementation of session management has an inefficiency that could lead to performance issues and excessive resource usage. Every time a user makes a request to the service using an access key and secret key, the system creates a new session: https://github.com/casdoor/casdoor/blob/ab5fcf848e05222b6cd5ab717767ebca9f5ac1a7/routers/auto_signin_filter.go#L78C3-L78C30

Same problem with client secrets: https://github.com/casdoor/casdoor/blob/ab5fcf848e05222b6cd5ab717767ebca9f5ac1a7/routers/auto_signin_filter.go#L88C1-L88C6

I suggest adopting a pattern similar to what Django uses, where the user data is stored inside the request context (ctx) and can be accessed across different controllers without needing to create a new session each time. This would not only improve performance but also reduce the load on our session storage, whether it's in-memory or in Redis.