/span>.ID); err != nil { return err } } return committer.Commit() } // DoctorUserStarNum recalculate Stars number for all user func DoctorUserStarNum() (err error) { const batchSize = 100 for start := 0; ; start += batchSize { users := make([]user_model.User, 0, batchSize) if err = db.GetEngine(db.DefaultContext).Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil { return } if len(users) == 0 { break } if err = updateUserStarNumbers(users); err != nil { return } } log.Debug("recalculate Stars number for all user finished") return } // DeleteDeployKey delete deploy keys func DeleteDeployKey(ctx context.Context, doer *user_model.User, id int64) error { key, err := asymkey_model.GetDeployKeyByID(ctx, id) if err != nil { if asymkey_model.IsErrDeployKeyNotExist(err) { return nil } return fmt.Errorf("GetDeployKeyByID: %v", err) } // Check if user has access to delete this key. if !doer.IsAdmin { repo, err := repo_model.GetRepositoryByIDCtx(ctx, key.RepoID) if err != nil { return fmt.Errorf("GetRepositoryByID: %v", err) } has, err := access_model.IsUserRepoAdmin(ctx, repo, doer) if err != nil { return fmt.Errorf("GetUserRepoPermission: %v", err) } else if !has { return asymkey_model.ErrKeyAccessDenied{ UserID: doer.ID, KeyID: key.ID, Note: "deploy", } } } if _, err := db.DeleteByBean(ctx, &asymkey_model.DeployKey{ ID: key.ID, }); err != nil { return fmt.Errorf("delete deploy key [%d]: %v", key.ID, err) } // Check if this is the last reference to same key content. has, err := asymkey_model.IsDeployKeyExistByKeyID(ctx, key.KeyID) if err != nil { return err } else if !has { if err = asymkey_model.DeletePublicKeys(ctx, key.KeyID); err != nil { return err } } return nil }