fix: [#840] DB cache is not reset when fresh orm#1322
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1322 +/- ##
=======================================
Coverage 69.95% 69.95%
=======================================
Files 282 282
Lines 16653 16653
=======================================
Hits 11649 11649
Misses 4516 4516
Partials 488 488 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request addresses issue #840 by adding a mechanism to reset the database connection cache when the ORM's Fresh method is called. The implementation migrates from a regular map to sync.Map for storing connections and introduces a new ResetConnections function.
Key changes:
- Introduced
ResetConnections()function to clear all cached GORM database connections - Modified connection storage from
map[string]*gorm.DBtosync.Map - Updated
Orm.Fresh()to calldriver.ResetConnections()for proper cache clearing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| database/driver/gorm.go | Migrated connectionToDB to sync.Map and added ResetConnections function to clear all cached database connections |
| database/orm/orm.go | Added import for database/driver package and integrated driver.ResetConnections() call into Fresh method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📑 Description
Closes goravel/goravel#840
This pull request introduces an improvement to the database connection handling by adding a mechanism to reset GORM connections, and integrates this reset into the ORM's
Freshmethod. The changes also include a minor import update.Database connection management improvements:
ResetConnectionsfunction todatabase/driver/gorm.gothat safely clears the internal map of GORM connections, allowing for a clean reset of database connections.Freshmethod inOrm(database/orm/orm.go) to calldriver.ResetConnections(), ensuring that all GORM connections are reset when refreshing the ORM state.Codebase maintenance:
github.com/goravel/framework/database/driverindatabase/orm/orm.goto support the new connection reset functionality.✅ Checks