Skip to content

Commit 3b3251f

Browse files
committed
cache introspection and generate in parallel
1 parent 7c84758 commit 3b3251f

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Tocsoft.GraphQLCodeGen.Cli/Program.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,23 @@ public static void MainApplication(CommandLineApplication app)
101101

102102
IEnumerable<CodeGeneratorSettings> settings = settingsLoader.GenerateSettings(loaderSettings, sourceArgument.Values);
103103
HashSet<string> generatedFiles = new HashSet<string>();
104-
foreach (CodeGeneratorSettings s in settings)
105-
{
106-
CodeGenerator generator = new CodeGenerator(consoleLoger, s);
107104

108-
if (await generator.GenerateAsync())
105+
var tasks = settings.Select(Generate).ToList();
106+
Task Generate(CodeGeneratorSettings s)
107+
{
108+
return Task.Run(async () =>
109109
{
110-
// generated code in here
111-
generatedFiles.Add(s.OutputPath);
112-
}
110+
CodeGenerator generator = new CodeGenerator(consoleLoger, s);
111+
if (await generator.GenerateAsync())
112+
{
113+
// generated code in here
114+
generatedFiles.Add(s.OutputPath);
115+
}
116+
});
113117
}
118+
119+
await Task.WhenAll(tasks);
120+
114121
if (inMsbuildMode)
115122
{
116123
foreach (string result in generatedFiles)

Tocsoft.GraphQLCodeGen.Cli/SchemaIntrospection/JsonIntrospection.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ public Task<string> LoadSchema(SchemaSource source)
1818
{
1919
if (!parseCache.TryGetValue(source.Location, out var schema))
2020
{
21-
schema = ConvertJsonToSchema(File.ReadAllText(source.Location));
22-
parseCache.Add(source.Location, schema);
21+
lock (parseCache)
22+
{
23+
if (!parseCache.TryGetValue(source.Location, out schema))
24+
{
25+
schema = ConvertJsonToSchema(File.ReadAllText(source.Location));
26+
parseCache.Add(source.Location, schema);
27+
}
28+
}
2329
}
2430
return Task.FromResult(schema);
2531
}

0 commit comments

Comments
 (0)