Skip to content

Commit

Permalink
fix: 避免越过tenantcache过期检查
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jun 2, 2020
1 parent 0d5be52 commit 8754ef2
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions pkg/cloudcommon/db/tenantcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,22 @@ func (manager *STenantCacheManager) fetchTenant(ctx context.Context, idStr strin
q = manager.GetTenantQuery()
}
q = filter(q)
tcnt, err := q.CountWithError()
caches := []STenant{}
err := FetchModelObjects(manager, q, &caches)
if err != nil {
return nil, errors.Wrap(err, "CountWithError")
return nil, errors.Wrap(err, "FetchModelObjects")
}
if tcnt > 1 {
return nil, errors.Wrapf(httperrors.ErrDuplicateName, "duplicate tenant/domain name (%d)", tcnt)
normal := []STenant{}
for _, cache := range caches {
if noExpireCheck || !cache.IsExpired() {
normal = append(normal, cache)
}
}
tobj, err := NewModelObject(manager)
if err != nil {
return nil, errors.Wrap(err, "NewModelObject")
if len(normal) > 1 {
return nil, errors.Wrapf(httperrors.ErrDuplicateName, "duplicate tenant/domain name (%d)", len(normal))
}
err = q.First(tobj)
if err != nil && err != sql.ErrNoRows {
return nil, errors.Wrap(err, "query")
} else if tobj != nil {
tenant := tobj.(*STenant)
if noExpireCheck || !tenant.IsExpired() {
return tenant, nil
}
if len(normal) == 1 {
return &normal[0], nil
}
if isDomain {
return manager.fetchDomainFromKeystone(ctx, idStr)
Expand Down

0 comments on commit 8754ef2

Please sign in to comment.