Skip to content

Commit

Permalink
cleanup empty users in database
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik Schwan committed Mar 16, 2021
1 parent e1ed44a commit ba988e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,16 @@ func (db *Database) AddRegistration(username, accountId, deviceToken string, mai
}

func (db *Database) DeleteIfExistRegistration(reg Registration) bool {
for _, user := range db.Users {
for username, user := range db.Users {
for accountId, account := range user.Accounts {
if accountId == reg.AccountId {
dbMutex.Lock()
log.Infoln("Deleting " + account.DeviceToken)
delete(user.Accounts, accountId)
// clean up empty users
if len(user.Accounts) == 0 {
delete(db.Users, username)
}
db.write()
dbMutex.Unlock()
return true
Expand Down

0 comments on commit ba988e9

Please sign in to comment.