Skip to content

Commit 4727377

Browse files
committed
Only clear version cache if it has elements & also only log it on that condition
1 parent 2e270a8 commit 4727377

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/Server/Services/GitLab/VersionCache.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void Init(ProjectId projectId) => Executor.ExecuteBackgroundAsync(async (
8181
{
8282
string howToRefresh = AdminEndpointMetadata.Enabled
8383
? $"using the {Constants.FullRouteName_Api_Admin_RefreshCache} endpoint or restarting the server."
84-
: "restarting the server. There is an admin-only endpoint available that has not been configured. Set an admin access token in appsettings.json to enable the endpoint.";
84+
: "restarting the server. Set an admin access token in appsettings.json to enable an endpoint to do this.";
8585

8686
_logger.LogInformation(
8787
"Periodic version cache refreshing is disabled for {project}. It can be refreshed by {means}",
@@ -112,7 +112,7 @@ public void Init(ProjectId projectId) => Executor.ExecuteBackgroundAsync(async (
112112
public async Task RefreshAsync()
113113
{
114114
await _semaphore.WaitAsync();
115-
115+
116116
_logger.LogInformation("Reloading version cache for {project}", _cachedProject!.Value.Name);
117117

118118
_latestTag = (await _gl.GetLatestReleaseAsync(_cachedProject.Value.Id))?.TagName;
@@ -123,9 +123,6 @@ public async Task RefreshAsync()
123123
return;
124124
}
125125

126-
_logger.LogInformation("Clearing {entryCount} version cache entries for {project}", Count,
127-
_cachedProject!.Value.Name);
128-
129126
var sw = Stopwatch.StartNew();
130127

131128
var releases = await _gl.PageReleases(_cachedProject.Value.Id)
@@ -135,10 +132,15 @@ public async Task RefreshAsync()
135132
Enum.GetName(code) ?? $"{(int)code}")
136133
);
137134

138-
if (releases == null)
135+
if (releases is null)
139136
goto ReleaseLock;
140-
141-
Clear();
137+
138+
if (Count > 0)
139+
{
140+
_logger.LogInformation("Clearing {entryCount} version cache entries for {project}", Count,
141+
_cachedProject!.Value.Name);
142+
Clear();
143+
}
142144

143145
foreach (var release in releases)
144146
{

0 commit comments

Comments
 (0)