Skip to content

Commit ad7ef3b

Browse files
authored
[supervisor] increase default workspace image cache duration and do prefetch (#18951)
1 parent 9b19c6b commit ad7ef3b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

components/supervisor/pkg/supervisor/services.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,15 @@ type InfoService struct {
653653
defaultWorkspaceImage string
654654
}
655655

656-
var infoCacheDuration = 5 * time.Second
656+
var infoCacheDuration = 30 * time.Second
657+
658+
func NewInfoService(cfg *Config, cstate ContentState, gitpodService serverapi.APIInterface) *InfoService {
659+
svc := &InfoService{cfg: cfg, ContentState: cstate, GitpodService: gitpodService}
660+
// it makes no sense to handle cancel here, just ignore the warning (find no way now to disable it)
661+
ctx, _ := context.WithTimeout(context.Background(), 15*time.Second)
662+
go svc.getDefaultWorkspaceImage(ctx)
663+
return svc
664+
}
657665

658666
// RegisterGRPC registers the gRPC info service.
659667
func (is *InfoService) RegisterGRPC(srv *grpc.Server) {
@@ -675,11 +683,10 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
675683
is.cacheMu.RUnlock()
676684

677685
is.cacheMu.Lock()
678-
defer is.cacheMu.Unlock()
679686
defer func() {
680687
is.cacheTimestamp = time.Now()
688+
is.cacheMu.Unlock()
681689
}()
682-
683690
if time.Since(is.cacheTimestamp) < infoCacheDuration {
684691
return is.defaultWorkspaceImage
685692
}
@@ -691,6 +698,8 @@ func (is *InfoService) getDefaultWorkspaceImage(ctx context.Context) string {
691698
wsImage, err := is.GitpodService.GetDefaultWorkspaceImage(ctx)
692699
if err == nil {
693700
is.defaultWorkspaceImage = wsImage
701+
} else {
702+
log.WithError(err).Error("failed to get default workspace image")
694703
}
695704
return is.defaultWorkspaceImage
696705
}

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func Run(options ...RunOption) {
384384
termMuxSrv,
385385
RegistrableTokenService{Service: tokenService},
386386
notificationService,
387-
&InfoService{cfg: cfg, ContentState: cstate, GitpodService: gitpodService},
387+
NewInfoService(cfg, cstate, gitpodService),
388388
&ControlService{portsManager: portMgmt},
389389
&portService{portsManager: portMgmt},
390390
}

0 commit comments

Comments
 (0)