Skip to content

Commit f48b301

Browse files
committed
All
- increase performance
1 parent 995943d commit f48b301

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

Common/Licensing/LicenseService.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ public LicenseService(GlobalSettingsService globalSettingsService)
2121
this.globalSettingsService = globalSettingsService;
2222
}
2323

24-
public async void Check()
24+
public Task Check()
2525
{
26-
try
26+
return Task.Factory.StartNew(() =>
2727
{
28-
this.license = await this.SendCommand<string>($"{this.globalSettingsService.Read().License}/check");
29-
this.waitForCheck.Set();
30-
}
31-
catch (Exception exception)
32-
{
33-
Logger.Warning(exception.Message + Environment.NewLine + exception.StackTrace);
34-
}
28+
try
29+
{
30+
this.license = this.SendCommand<string>($"{this.globalSettingsService.Read().License}/check").Result;
31+
this.waitForCheck.Set();
32+
}
33+
catch (Exception exception)
34+
{
35+
Logger.Warning(exception.Message + Environment.NewLine + exception.StackTrace);
36+
}
37+
});
3538
}
3639

3740
public string Get()

TypeScript/Helpers/TypeScriptStrictHelper.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using KY.Core.DataAccess;
34
using KY.Core.Dependency;
45
using KY.Generator.Output;
56
using KY.Generator.Transfer;
7+
using KY.Generator.TypeScript.Transfer;
68
using KY.Generator.TypeScript.Transfer.Readers;
79

810
namespace KY.Generator.TypeScript
911
{
1012
public static class TypeScriptStrictHelper
1113
{
14+
private static readonly Dictionary<string, TsConfig> cache = new();
15+
1216
public static void SetStrict(this IOptions options, string relativePath, IDependencyResolver resolver)
1317
{
1418
if (options.IsStrictSet)
@@ -22,7 +26,18 @@ public static bool Read(string relativePath, IDependencyResolver resolver)
2226
{
2327
if (resolver.Get<IOutput>() is FileOutput fileOutput)
2428
{
25-
return resolver.Create<TsConfigReader>().Read(FileSystem.Combine(fileOutput.BasePath, relativePath))?.CompilerOptions?.Strict ?? false;
29+
string fullPath = FileSystem.Combine(fileOutput.BasePath, relativePath);
30+
TsConfig tsConfig = cache.FirstOrDefault(x => fullPath.StartsWith(x.Key)).Value;
31+
if (tsConfig == null)
32+
{
33+
tsConfig = resolver.Create<TsConfigReader>().Read(fullPath);
34+
if (tsConfig != null)
35+
{
36+
string basePath = FileSystem.GetDirectoryName(tsConfig.Path);
37+
cache[basePath] = tsConfig;
38+
}
39+
}
40+
return tsConfig?.CompilerOptions?.Strict ?? false;
2641
}
2742
return false;
2843
}

TypeScript/Transfer/Readers/TsConfigReader.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ private TsConfig Parse(string path)
5454
{
5555
string text = FileSystem.ReadAllText(path);
5656
TsConfig tsConfig = JsonConvert.DeserializeObject<TsConfig>(text);
57-
transferObjects.Add(tsConfig);
57+
if (tsConfig != null)
58+
{
59+
tsConfig.Path = path;
60+
transferObjects.Add(tsConfig);
61+
}
5862
Logger.Trace($"Activate TypeScript {(tsConfig?.CompilerOptions?.Strict == true ? "strict" : "regular")} mode");
5963
return tsConfig;
6064
}

TypeScript/Transfer/TsConfig.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace KY.Generator.TypeScript.Transfer
44
{
55
public class TsConfig : ITransferObject
66
{
7+
public string Path { get; set; }
78
public CompilerOptions CompilerOptions { get; set; } = new();
89
}
910

0 commit comments

Comments
 (0)