Add generic set type (#21408)

This PR adds a generic set type to get rid of maps used as sets.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
KN4CK3R 2022-10-12 07:18:26 +02:00 committed by GitHub
parent e84558b093
commit 0e57ff7eee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 328 additions and 324 deletions

View file

@ -15,6 +15,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@ -209,7 +210,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
return fmt.Errorf("AddReleaseAttachments: %v", err)
}
deletedUUIDsMap := make(map[string]bool)
deletedUUIDs := make(container.Set[string])
if len(delAttachmentUUIDs) > 0 {
// Check attachments
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, delAttachmentUUIDs)
@ -220,7 +221,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
if attach.ReleaseID != rel.ID {
return errors.New("delete attachement of release permission denied")
}
deletedUUIDsMap[attach.UUID] = true
deletedUUIDs.Add(attach.UUID)
}
if _, err := repo_model.DeleteAttachments(ctx, attachments, false); err != nil {
@ -245,7 +246,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
}
for uuid, newName := range editAttachments {
if !deletedUUIDsMap[uuid] {
if !deletedUUIDs.Contains(uuid) {
if err = repo_model.UpdateAttachmentByUUID(ctx, &repo_model.Attachment{
UUID: uuid,
Name: newName,