fix: [#676] Unnecessary Redis connection attempt on startup despite SESSION_DRIVER=file#1043
fix: [#676] Unnecessary Redis connection attempt on startup despite SESSION_DRIVER=file#1043
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 5197b21 | Previous: 88c15e8 | Ratio |
|---|---|---|---|
BenchmarkSession_ManagerInteraction |
537.6 ns/op 240 B/op 5 allocs/op |
null ns/op 0 B/op 0 allocs/op |
+∞ |
BenchmarkSession_ManagerInteraction - ns/op |
537.6 ns/op |
null ns/op |
+∞ |
BenchmarkSession_ManagerInteraction - B/op |
240 B/op |
0 B/op |
+∞ |
BenchmarkSession_ManagerInteraction - allocs/op |
5 allocs/op |
0 allocs/op |
+∞ |
This comment was automatically generated by workflow using github-action-benchmark.
| // Driver retrieves the session driver by name. | ||
| Driver(name ...string) (Driver, error) | ||
| // Extend extends the session manager with a custom driver. | ||
| Extend(driver string, handler func() Driver) error |
There was a problem hiding this comment.
The Extend method should extend driver type: file, custom instead of a specific driver(current logic), so remove it for now, user should use the custom driver to extend custom handler.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1043 +/- ##
==========================================
+ Coverage 70.49% 70.54% +0.04%
==========================================
Files 176 176
Lines 12343 12330 -13
==========================================
- Hits 8701 8698 -3
+ Misses 3261 3252 -9
+ Partials 381 380 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📑 Description
Closes goravel/goravel#676
The root reason is that the redis driver is initialized even if the session driver is file. We cancel the initial process in this PR.
This pull request refactors the session management system to simplify configuration handling, improve driver registration, and update related tests. Key changes include replacing dynamic configuration lookups with cached properties, removing unused methods, and updating tests to align with the new implementation.
Refactoring of session management:
Extendmethod from theManagerinterface and its implementation, simplifying the driver registration process. (contracts/session/manager.go,session/manager.go) [1] [2]cookie,defaultDriver,gcInterval,lifetime) as properties in theManagerstruct to reduce repeated lookups. (session/manager.go)getDefaultDriverandregisterConfiguredDriversmethods with a streamlinedregisterDrivermethod for registering individual drivers. (session/manager.go) [1] [2]Updates to session behavior:
BuildSessionmethod to use the cachedcookieproperty instead of fetching it dynamically. (session/manager.go)gcIntervalandlifetimeproperties. (session/manager.go)Improvements to tests:
EXPECT()for better test reliability and readability. (session/manager_test.go,session/middleware/start_session_test.go) [1] [2]ExtendandgetDefaultDriver. (session/manager_test.go)session/manager_test.go,session/middleware/start_session_test.go) [1] [2]Middleware adjustments:
StartSessionmiddleware to use default values forsession.lifetimeif not explicitly provided. (session/middleware/start_session.go)✅ Checks