Skip to content

Commit

Permalink
⚡ graphAppInitializer: initialize apps on separate threads for faster…
Browse files Browse the repository at this point in the history
… startup
  • Loading branch information
ujibang committed Sep 26, 2024
1 parent 94f3d20 commit 75438cd
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.restheart.plugins.OnInit;
import org.restheart.plugins.PluginsRegistry;
import org.restheart.plugins.RegisterPlugin;
import org.restheart.utils.ThreadsUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -90,14 +91,16 @@ public void init() {
.withDocumentClass(BsonDocument.class)
.find()
.forEach(appDef -> {
try {
var app = AppBuilder.build(appDef);
var appUri = app.getDescriptor().getUri() != null ? app.getDescriptor().getUri() : app.getDescriptor().getAppName();
AppDefinitionLoadingCache.getCache().put(appUri, app);
LOGGER.debug("GQL App Definition {} initialized", appUri);
} catch (GraphQLIllegalAppDefinitionException e) {
LOGGER.warn("GQL App Definition {} is invalid", appDef.get("_id"), e);
}
ThreadsUtils.virtualThreadsExecutor().execute(() -> {
try {
var app = AppBuilder.build(appDef);
var appUri = app.getDescriptor().getUri() != null ? app.getDescriptor().getUri() : app.getDescriptor().getAppName();
AppDefinitionLoadingCache.getCache().put(appUri, app);
LOGGER.debug("GQL App Definition {} initialized", appUri);
} catch (GraphQLIllegalAppDefinitionException e) {
LOGGER.warn("GQL App Definition {} is invalid", appDef.get("_id"), e);
}
});
});
}
}
Expand Down

0 comments on commit 75438cd

Please sign in to comment.