Skip to content

Commit

Permalink
remove not needed length check
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfHammer committed Sep 19, 2024
1 parent 11a962b commit 863e518
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
8 changes: 3 additions & 5 deletions internal/cf/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ func (c *spaceClient) GetBinding(ctx context.Context, bindingOpts map[string]str
if c.resourceCache.isCacheExpired(bindingType) {
populateResourceCache[*spaceClient](c, bindingType, "")
}
if len(c.resourceCache.getCachedBindings()) != 0 {
binding, inCache := c.resourceCache.getBindingFromCache(bindingOpts["owner"])
if inCache {
return binding, nil
}
binding, inCache := c.resourceCache.getBindingFromCache(bindingOpts["owner"])
if inCache {
return binding, nil
}
}

Expand Down
10 changes: 2 additions & 8 deletions internal/cf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,37 +275,31 @@ type manageResourceCache interface {

func populateResourceCache[T manageResourceCache](c T, resourceType cacheResourceType, username string) {
ctx := context.Background()

var err error

switch resourceType {
case bindingType:
if client, ok := any(c).(ResourceServicesClient[T]); ok {
err = client.populateServiceBindings(ctx)
//TODO:remove later
fmt.Println("populate service binding finished")
}
case instanceType:
if client, ok := any(c).(ResourceServicesClient[T]); ok {
err = client.populateServiceInstances(ctx)
//TODO:remove later
fmt.Println("populate service instance finished")
}
case spaceType:
if client, ok := any(c).(ResourceSpaceClient[T]); ok {
err = client.populateSpaces(ctx)
//TODO:remove later
fmt.Println("populate space finished")
}
case spaceUserRoleType:
if client, ok := any(c).(ResourceSpaceClient[T]); ok {
err = client.populateSpaceUserRoleCache(ctx, username)
fmt.Println("populate service spaceUserRoles finished")
}
}

if err != nil {
// reset the cache to nil in case of error
log.Printf("Error populating %s: %s", resourceType, err)
log.Printf("Error populating cache for type %s: %s", resourceType, err)
c.resetCache(resourceType)
return
}
Expand Down
8 changes: 3 additions & 5 deletions internal/cf/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ func (c *spaceClient) GetInstance(ctx context.Context, instanceOpts map[string]s
if c.resourceCache.isCacheExpired(instanceType) {
populateResourceCache[*spaceClient](c, instanceType, "")
}
if len(c.resourceCache.getCachedInstances()) != 0 {
instance, inCache := c.resourceCache.getInstanceFromCache(instanceOpts["owner"])
if inCache {
return instance, nil
}
instance, inCache := c.resourceCache.getInstanceFromCache(instanceOpts["owner"])
if inCache {
return instance, nil
}
}

Expand Down
5 changes: 1 addition & 4 deletions internal/cf/resourcecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func (c *resourceCache) setLastCacheTime(resourceType cacheResourceType) {
case spaceUserRoleType:
c.spaceUserRoleLastCacheTime = now
}
//TODO:remove later
fmt.Printf("Last cache time for %s: %v\n", resourceType, now)
}

// isCacheExpired checks if the cache is expired for a specific resource type
Expand All @@ -129,9 +127,8 @@ func (c *resourceCache) isCacheExpired(resourceType cacheResourceType) bool {
}

expirationTime := lastCacheTime.Add(c.cacheTimeOut)
//TODO:remove later
fmt.Printf("Expiration time for %s: %v and last cached time: %v and timenow :%v\n", resourceType, expirationTime, lastCacheTime, time.Now())
isExpired := time.Now().After(expirationTime)

return isExpired
}

Expand Down
11 changes: 6 additions & 5 deletions internal/cf/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ func (c *organizationClient) GetSpace(ctx context.Context, owner string) (*facad
if c.resourceCache.isCacheExpired(spaceType) {
populateResourceCache[*organizationClient](c, spaceType, "")
}
if len(c.resourceCache.getCachedSpaces()) != 0 {
space, inCache := c.resourceCache.getSpaceFromCache(owner)
if inCache {
return space, nil
}
space, inCache := c.resourceCache.getSpaceFromCache(owner)
if inCache {
return space, nil
}
}

Expand All @@ -45,6 +43,7 @@ func (c *organizationClient) GetSpace(ctx context.Context, owner string) (*facad
}
space := spaces[0]

// TODO: add directly to cache
return InitSpace(space, owner)
}

Expand All @@ -69,6 +68,8 @@ func (c *organizationClient) CreateSpace(ctx context.Context, name string, owner
WithAnnotation(annotationPrefix, annotationKeyGeneration, strconv.FormatInt(generation, 10))

_, err = c.client.Spaces.Create(ctx, req)
// do not add space to the cache here because we wait until the space GUID is known

return err
}

Expand Down

0 comments on commit 863e518

Please sign in to comment.