@@ -647,8 +647,14 @@ type InfoService struct {
647
647
GitpodService serverapi.APIInterface
648
648
649
649
api.UnimplementedInfoServiceServer
650
+
651
+ cacheMu sync.RWMutex
652
+ cacheTimestamp time.Time
653
+ defaultWorkspaceImage string
650
654
}
651
655
656
+ var infoCacheDuration = 5 * time .Second
657
+
652
658
// RegisterGRPC registers the gRPC info service.
653
659
func (is * InfoService ) RegisterGRPC (srv * grpc.Server ) {
654
660
api .RegisterInfoServiceServer (srv , is )
@@ -659,20 +665,34 @@ func (is *InfoService) RegisterREST(mux *runtime.ServeMux, grpcEndpoint string)
659
665
return api .RegisterInfoServiceHandlerFromEndpoint (context .Background (), mux , grpcEndpoint , []grpc.DialOption {grpc .WithTransportCredentials (insecure .NewCredentials ())})
660
666
}
661
667
662
- func (is * InfoService ) getDefaultWorkspaceImage (ctx context.Context ) (defaultWorkspaceImage string ) {
663
- defaultWorkspaceImage = is .cfg .DefaultWorkspaceImage
664
- if defaultWorkspaceImage == "" {
665
- // TODO: delete-me, added for compatibility before server is deployed / rollback
666
- defaultWorkspaceImage = "gitpod/workspace-full:latest"
668
+ func (is * InfoService ) getDefaultWorkspaceImage (ctx context.Context ) string {
669
+ is .cacheMu .RLock ()
670
+
671
+ if time .Since (is .cacheTimestamp ) < infoCacheDuration {
672
+ is .cacheMu .RUnlock ()
673
+ return is .defaultWorkspaceImage
667
674
}
675
+ is .cacheMu .RUnlock ()
676
+
677
+ is .cacheMu .Lock ()
678
+ defer is .cacheMu .Unlock ()
679
+ defer func () {
680
+ is .cacheTimestamp = time .Now ()
681
+ }()
682
+
683
+ if time .Since (is .cacheTimestamp ) < infoCacheDuration {
684
+ return is .defaultWorkspaceImage
685
+ }
686
+
687
+ is .defaultWorkspaceImage = is .cfg .DefaultWorkspaceImage
668
688
if is .GitpodService == nil {
669
- return
689
+ return is . defaultWorkspaceImage
670
690
}
671
691
wsImage , err := is .GitpodService .GetDefaultWorkspaceImage (ctx )
672
692
if err == nil {
673
- defaultWorkspaceImage = wsImage
693
+ is . defaultWorkspaceImage = wsImage
674
694
}
675
- return
695
+ return is . defaultWorkspaceImage
676
696
}
677
697
678
698
// WorkspaceInfo provides information about the workspace.
0 commit comments