Skip to content

Commit c624fbf

Browse files
committed
enhance: hash repo's setting in background because we do not need it immediately.
Signed-off-by: leo <longshuang@msn.cn>
1 parent 3b3fac6 commit c624fbf

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Models/RepositorySettings.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static RepositorySettings Get(string gitCommonDir)
8181

8282
if (!File.Exists(fullpath))
8383
{
84-
setting = new RepositorySettings();
84+
setting = new();
8585
}
8686
else
8787
{
@@ -92,12 +92,18 @@ public static RepositorySettings Get(string gitCommonDir)
9292
}
9393
catch
9494
{
95-
setting = new RepositorySettings();
95+
setting = new();
9696
}
9797
}
9898

99+
// Serialize setting again to make sure there are no unnecessary whitespaces.
100+
Task.Run(() =>
101+
{
102+
var formatted = JsonSerializer.Serialize(setting, JsonCodeGen.Default.RepositorySettings);
103+
setting._orgHash = HashContent(formatted);
104+
});
105+
99106
setting._file = fullpath;
100-
setting._orgHash = HashContent(JsonSerializer.Serialize(setting, JsonCodeGen.Default.RepositorySettings));
101107
_cache.Add(fullpath, setting);
102108
return setting;
103109
}
@@ -106,8 +112,8 @@ public async Task SaveAsync()
106112
{
107113
try
108114
{
109-
string content = JsonSerializer.Serialize(this, JsonCodeGen.Default.RepositorySettings);
110-
string hash = HashContent(content);
115+
var content = JsonSerializer.Serialize(this, JsonCodeGen.Default.RepositorySettings);
116+
var hash = HashContent(content);
111117
if (!hash.Equals(_orgHash, StringComparison.Ordinal))
112118
{
113119
await File.WriteAllTextAsync(_file, content);

0 commit comments

Comments
 (0)