File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
graphile-build-pg/src/plugins Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -861,7 +861,7 @@ export default (async function PgIntrospectionPlugin(
861
861
this . _start ( ) ;
862
862
}
863
863
864
- async _start ( ) {
864
+ async _start ( isReconnect = false ) {
865
865
if ( this . stopped ) {
866
866
return ;
867
867
}
@@ -921,7 +921,9 @@ export default (async function PgIntrospectionPlugin(
921
921
}
922
922
923
923
// Trigger re-introspection on server reconnect
924
- this . _handleChange ( ) ;
924
+ if ( isReconnect ) {
925
+ this . _handleChange ( ) ;
926
+ }
925
927
}
926
928
} catch ( e ) {
927
929
// If something goes wrong, disconnect and try again after a short delay
@@ -949,7 +951,7 @@ export default (async function PgIntrospectionPlugin(
949
951
setTimeout ( ( ) => {
950
952
if ( ! this . stopped ) {
951
953
// Listen for further changes
952
- this . _start ( ) ;
954
+ this . _start ( true ) ;
953
955
}
954
956
} , 2000 ) ;
955
957
}
Original file line number Diff line number Diff line change @@ -510,7 +510,15 @@ class SchemaBuilder extends EventEmitter {
510
510
try {
511
511
this . _busy = true ;
512
512
this . _explicitSchemaListener = listener ;
513
+
514
+ // We want to ignore `triggerChange` calls that occur whilst we're setting
515
+ // up the listeners to prevent an unnecessary double schema build.
516
+ let ignoreChangeTriggers = true ;
517
+
513
518
this . triggerChange = ( ) => {
519
+ if ( ignoreChangeTriggers ) {
520
+ return ;
521
+ }
514
522
this . _generatedSchema = null ;
515
523
// XXX: optionally debounce
516
524
try {
@@ -530,10 +538,16 @@ class SchemaBuilder extends EventEmitter {
530
538
for ( const fn of this . watchers ) {
531
539
await fn ( this . triggerChange ) ;
532
540
}
541
+
542
+ // Now we're about to build the first schema, any further `triggerChange`
543
+ // calls should be honoured.
544
+ ignoreChangeTriggers = false;
545
+
533
546
if (listener) {
534
547
this . on ( "schema" , listener ) ;
535
548
}
536
549
this.emit("schema", this.buildSchema());
550
+
537
551
this._watching = true;
538
552
} finally {
539
553
this . _busy = false ;
You can’t perform that action at this time.
0 commit comments