@@ -285,6 +285,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
285
285
286
286
private readonly disposables = new DisposableCollection ( ) ;
287
287
288
+ private shouldNotifyClients = false ;
289
+
288
290
dispose ( ) : void {
289
291
this . disposables . dispose ( ) ;
290
292
}
@@ -309,12 +311,20 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
309
311
log . debug ( { userId : this . userID } , `clientRegion: ${ clientHeaderFields . clientRegion } ` ) ;
310
312
log . debug ( { userId : this . userID } , "initializeClient" ) ;
311
313
312
- this . listenForWorkspaceInstanceUpdates ( ) ;
314
+ if ( this . client && clientMetadata . type === "browser" ) {
315
+ this . shouldNotifyClients = true ;
316
+ }
313
317
314
- this . listenForPrebuildUpdates ( ) . catch ( ( err ) => log . error ( "error registering for prebuild updates" , err ) ) ;
318
+ if ( this . shouldNotifyClients ) {
319
+ this . listenForWorkspaceInstanceUpdates ( ) ;
320
+ this . listenForPrebuildUpdates ( ) . catch ( ( err ) => log . error ( "error registering for prebuild updates" , err ) ) ;
321
+ }
315
322
}
316
323
317
324
private async listenForPrebuildUpdates ( ) {
325
+ if ( ! this . shouldNotifyClients ) {
326
+ return ;
327
+ }
318
328
// 'registering for prebuild updates for all projects this user has access to
319
329
const projects = await this . getAccessibleProjects ( ) ;
320
330
@@ -331,7 +341,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
331
341
) ;
332
342
333
343
for ( const projectId of projects ) {
334
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ] ) ;
344
+ this . disposables . push ( this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ) ;
335
345
}
336
346
337
347
// TODO(at) we need to keep the list of accessible project up to date
@@ -453,7 +463,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
453
463
// Once we have those, we should remove this.
454
464
//
455
465
const ws = await this . workspaceDb . trace ( ctx ) . findById ( workspaceID ) ;
456
- if ( ! ! ws && ! ! wsi && ws . ownerId !== this . userID ) {
466
+ const relatedPrebuildFound = ! ! ws && ! ! wsi && ws . ownerId !== this . userID ;
467
+ if ( this . client && relatedPrebuildFound ) {
457
468
const resetListenerFromRedis = this . subscriber . listenForWorkspaceInstanceUpdates (
458
469
ws . ownerId ,
459
470
( ctx , instance ) => {
@@ -529,7 +540,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
529
540
}
530
541
531
542
private listenForWorkspaceInstanceUpdates ( ) : void {
532
- if ( ! this . userID || ! this . client ) {
543
+ if ( ! this . shouldNotifyClients || ! this . userID ) {
533
544
return ;
534
545
}
535
546
@@ -3046,19 +3057,23 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3046
3057
}
3047
3058
3048
3059
const project = await this . projectsService . createProject ( params , user ) ;
3060
+
3049
3061
// update client registration for the logged in user
3050
- const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3051
- TraceContext . withSpan (
3052
- "forwardPrebuildUpdateToClient" ,
3053
- ( ctx ) => {
3054
- traceClientMetadata ( ctx , this . clientMetadata ) ;
3055
- TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3062
+ if ( this . shouldNotifyClients ) {
3063
+ const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3064
+ TraceContext . withSpan (
3065
+ "forwardPrebuildUpdateToClient" ,
3066
+ ( ctx ) => {
3067
+ traceClientMetadata ( ctx , this . clientMetadata ) ;
3068
+ TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3069
+
3070
+ this . client ?. onPrebuildUpdate ( update ) ;
3071
+ } ,
3072
+ ctx ,
3073
+ ) ;
3056
3074
3057
- this . client ?. onPrebuildUpdate ( update ) ;
3058
- } ,
3059
- ctx ,
3060
- ) ;
3061
- this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
3075
+ this . disposables . pushAll ( [ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ] ) ;
3076
+ }
3062
3077
3063
3078
return project ;
3064
3079
}
0 commit comments