-
Notifications
You must be signed in to change notification settings - Fork 468
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
Add batch save/update for groups and users #2245
Conversation
The method SaveAccount in user.go and group.go files was split into two separate methods. Now, user-specific data is handled by SaveUsers and group-specific data is handled by SaveGroups method. This provides a cleaner and more efficient way to save user and group data.
management/server/sql_store.go
Outdated
|
||
// SaveGroups saves the given list of groups to the database. | ||
// It updates existing groups if a conflict occurs. | ||
func (s *SqlStore) SaveGroups(account *Account) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is not memory efficient. If I understand well the reason of the "G" postfix it is just used by the Gorm. So after that, we always need to clean up because the garbage collector will not do it. Nevertheless, we should not mix the layers. The account structure holds the account info and the SQL-related things. We should create separate struct definition just for the SQL. It is more code but at the end, it will be safer.
Now I recommend to:
- change the parameters of the function *SaveGroups(accountID string, groups map[string]nbgroup.Group)
- create a new slice []nbgroup.Group
- copy the relevant data to there
- change the db.clauses to use the new slice
So after it the GroupsG will be empty again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the "&gorm.Session{FullSaveAssociations: true}" keyword help to you
management/server/sql_store.go
Outdated
@@ -311,6 +311,32 @@ func (s *SqlStore) SavePeerLocation(accountID string, peerWithLocation *nbpeer.P | |||
return nil | |||
} | |||
|
|||
// SaveUsers saves the given list of users to the database. | |||
// It updates existing users if a conflict occurs. | |||
func (s *SqlStore) SaveUsers(account *Account) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same like groups
management/server/sql_store.go
Outdated
func (s *SqlStore) SaveGroups(accountID string, groups map[string]*nbgroup.Group) error { | ||
groupsToSave := make([]nbgroup.Group, 0, len(groups)) | ||
for id, group := range groups { | ||
group.ID = id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to do this operation? In this line I think we fill well the variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily needed, but it was to make sure the group ID is the same as the index
management/server/sql_store.go
Outdated
@@ -653,6 +683,8 @@ func (s *SqlStore) GetStoreEngine() StoreEngine { | |||
return s.storeEngine | |||
} | |||
|
|||
//func (s *SqlStore) SaveGroups() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment
|
* upstream/main: Add batch save/update for groups and users (netbirdio#2245) Limit GUI process execution to one per UID (netbirdio#2267) Add logging option for wg device (netbirdio#2271) fix 2260: fallback serial to Board (netbirdio#2263) Support DNS routes on iOS (netbirdio#2254) Fix parameter limit issue for Postgres store (netbirdio#2261) Bump google.golang.org/grpc from 1.64.0 to 1.64.1 (netbirdio#2248) Get client ui locale on windows natively (netbirdio#2251)
Describe your changes
Issue ticket number and link
Checklist