Merge pull request #12424 from heww/fix-issue-12292

fix(quota): fix internal server error when delete project
This commit is contained in:
He Weiwei 2020-07-08 19:50:03 +08:00 committed by GitHub
commit fc34a99de3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -50,7 +50,7 @@ func getProjectsBatchFn(ctx context.Context, keys dataloader.Keys) []*dataloader
projectIDs = append(projectIDs, id) projectIDs = append(projectIDs, id)
} }
projects, err := dao.GetProjects(&models.ProjectQueryParam{}) projects, err := dao.GetProjects(&models.ProjectQueryParam{ProjectIDs: projectIDs})
if err != nil { if err != nil {
return handleError(err) return handleError(err)
} }
@ -154,7 +154,7 @@ func (d *driver) Validate(hardLimits types.ResourceList) error {
func newDriver() dr.Driver { func newDriver() dr.Driver {
cfg := config.NewDBCfgManager() cfg := config.NewDBCfgManager()
loader := dataloader.NewBatchedLoader(getProjectsBatchFn) loader := dataloader.NewBatchedLoader(getProjectsBatchFn, dataloader.WithClearCacheOnBatch())
return &driver{cfg: cfg, loader: loader} return &driver{cfg: cfg, loader: loader}
} }

View File

@ -292,11 +292,6 @@ func (p *ProjectAPI) Delete() {
return return
} }
if err = p.ProjectMgr.Delete(p.project.ProjectID); err != nil {
p.ParseAndHandleError(fmt.Sprintf("failed to delete project %d", p.project.ProjectID), err)
return
}
quotaMgr, err := quota.NewManager("project", strconv.FormatInt(p.project.ProjectID, 10)) quotaMgr, err := quota.NewManager("project", strconv.FormatInt(p.project.ProjectID, 10))
if err != nil { if err != nil {
p.SendInternalServerError(fmt.Errorf("failed to get quota manager: %v", err)) p.SendInternalServerError(fmt.Errorf("failed to get quota manager: %v", err))
@ -307,6 +302,11 @@ func (p *ProjectAPI) Delete() {
return return
} }
if err = p.ProjectMgr.Delete(p.project.ProjectID); err != nil {
p.ParseAndHandleError(fmt.Sprintf("failed to delete project %d", p.project.ProjectID), err)
return
}
go func() { go func() {
if err := dao.AddAccessLog(models.AccessLog{ if err := dao.AddAccessLog(models.AccessLog{
Username: p.SecurityCtx.GetUsername(), Username: p.SecurityCtx.GetUsername(),