feat: [CDE-202]: infra provider resource cache (#2639)

* feat: [CDE-202]: infra provider resource cache
* feat: [CDE-202]: infra provider resource cache
CODE-2402
Ansuman Satapathy 2024-09-03 11:58:48 +00:00 committed by Harness
parent 5cfd41ae1a
commit ec7eca7491
3 changed files with 11 additions and 6 deletions

View File

@ -40,7 +40,7 @@ func (c *Controller) Find(
return nil, fmt.Errorf("failed to authorize: %w", err)
}
res, err := c.gitspaceSvc.Find(ctx, space.ID, identifier)
res, err := c.gitspaceSvc.Find(ctx, space.Path, identifier)
if err != nil {
return nil, fmt.Errorf("failed to find gitspace: %w", err)
}

View File

@ -27,12 +27,16 @@ import (
func (c *Service) Find(
ctx context.Context,
spaceID int64,
spaceRef string,
identifier string,
) (*types.GitspaceConfig, error) {
var gitspaceConfigResult *types.GitspaceConfig
txErr := c.tx.WithTx(ctx, func(ctx context.Context) error {
gitspaceConfig, err := c.gitspaceConfigStore.FindByIdentifier(ctx, spaceID, identifier)
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
if err != nil {
return fmt.Errorf("failed to find space: %w", err)
}
gitspaceConfig, err := c.gitspaceConfigStore.FindByIdentifier(ctx, space.ID, identifier)
if err != nil {
return fmt.Errorf("failed to find gitspace config: %w", err)
}
@ -52,6 +56,7 @@ func (c *Service) Find(
gitspaceConfig.State = enum.GitspaceStateUninitialized
}
gitspaceConfigResult = gitspaceConfig
gitspaceConfig.SpacePath = space.Path
return nil
}, dbtx.TxDefaultReadOnly)
if txErr != nil {

View File

@ -35,7 +35,7 @@ func (s *Service) handleGitspaceInfraEvent(
payload := event.Payload
config, fetchErr := s.getConfig(
ctx, payload.Infra.SpaceID, payload.Infra.GitspaceConfigIdentifier)
ctx, payload.Infra.SpacePath, payload.Infra.GitspaceConfigIdentifier)
if fetchErr != nil {
return fetchErr
}
@ -95,10 +95,10 @@ func (s *Service) handleGitspaceInfraEvent(
func (s *Service) getConfig(
ctx context.Context,
spaceID int64,
spaceRef string,
identifier string,
) (*types.GitspaceConfig, error) {
config, err := s.gitspaceSvc.Find(ctx, spaceID, identifier)
config, err := s.gitspaceSvc.Find(ctx, spaceRef, identifier)
if err != nil {
return nil, fmt.Errorf(
"failed to find gitspace config during infra event handling, identifier %s: %w", identifier, err)