Skip to content

Commit

Permalink
perf: Optimized the startup time of the tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
real-zony committed May 25, 2023
1 parent 6e2848a commit b240564
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ZonyLrcTools.Common/Updater/DefaultUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class DefaultUpdater : IUpdater, ISingletonDependency

public async Task CheckUpdateAsync()
{
if (!IsCheckUpdate())
{
return;
}

var response = await _warpHttpClient.GetAsync<NewVersionResponse?>(UpdateUrl);
if (response == null)
{
Expand Down Expand Up @@ -56,4 +61,27 @@ public async Task CheckUpdateAsync()
}
}
}

private bool IsCheckUpdate()
{
var lockFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "update.lock");

if (!File.Exists(lockFile))
{
File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}

if (long.TryParse(File.ReadAllText(lockFile), out var time))
{
var now = DateTimeOffset.Now.ToUnixTimeSeconds();
if (now - time <= 86400 /* 1 Day */)
{
return false;
}
}

File.WriteAllText(lockFile, DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
return true;
}
}

0 comments on commit b240564

Please sign in to comment.