GODT-1840: Safe map for mailboxID cache

This commit is contained in:
Jakub
2022-08-31 15:48:40 +02:00
parent 13ba2182c2
commit bcf799732f
7 changed files with 154 additions and 10 deletions

View File

@ -80,8 +80,10 @@ func (ctl *Controller) AddUserLabel(username string, label *pmapi.Label) error {
ctl.labelsByUsername[username] = []*pmapi.Label{}
}
userLabels := ctl.labelsByUsername[username]
labelName := getLabelNameWithoutPrefix(label.Name)
for _, existingLabel := range ctl.labelsByUsername[username] {
for _, existingLabel := range userLabels {
if existingLabel.Name == labelName {
return fmt.Errorf("folder or label %s already exists", label.Name)
}
@ -97,7 +99,9 @@ func (ctl *Controller) AddUserLabel(username string, label *pmapi.Label) error {
if label.Path == "" {
label.Path = label.Name
}
ctl.labelsByUsername[username] = append(ctl.labelsByUsername[username], label)
userLabels = append(userLabels, label)
ctl.labelsByUsername[username] = userLabels
ctl.resetUsers()
return nil
}

View File

@ -88,7 +88,7 @@ func (api *FakePMAPI) listLabels(_ context.Context, labeType string, route strin
if err := api.checkAndRecordCall(GET, route+"/"+labeType, nil); err != nil {
return nil, err
}
return api.labels, nil
return append([]*pmapi.Label{}, api.labels...), nil
}
func (api *FakePMAPI) createLabel(_ context.Context, label *pmapi.Label, route string) (*pmapi.Label, error) {