From 02dbc29582a6c5a228ee8dcd15b14d3cf0cb2249 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 31 Aug 2024 22:20:52 -0400 Subject: [PATCH] Fix client caching with app installation tokens --- .../Utils/GitHub/GitHubClientFactory.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Tgstation.Server.Host/Utils/GitHub/GitHubClientFactory.cs b/src/Tgstation.Server.Host/Utils/GitHub/GitHubClientFactory.cs index 4cf31a5d289..8e222609daf 100644 --- a/src/Tgstation.Server.Host/Utils/GitHub/GitHubClientFactory.cs +++ b/src/Tgstation.Server.Host/Utils/GitHub/GitHubClientFactory.cs @@ -22,10 +22,10 @@ namespace Tgstation.Server.Host.Utils.GitHub sealed class GitHubClientFactory : IGitHubClientFactory, IDisposable { /// - /// Limit to the amount of days a can live in the . + /// Limit to the amount of hours a can live in the . /// - /// God forbid someone leak server memory by constantly changing an instance's GitHub token. - const uint ClientCacheDays = 7; + /// Set to app installation token lifetime, which is the lowest. See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app. + const uint ClientCacheHours = 1; /// /// The used in place of when accessing a configuration-based client with no token set in . @@ -220,7 +220,7 @@ public async ValueTask CreateClient(string accessToken, Cancellat // Prune the cache var purgeCount = 0U; - var purgeAfter = now.AddDays(-ClientCacheDays); + var purgeAfter = now.AddHours(-ClientCacheHours); foreach (var key in clientCache.Keys.ToList()) { if (key == cacheKey) @@ -236,9 +236,9 @@ public async ValueTask CreateClient(string accessToken, Cancellat if (purgeCount > 0) logger.LogDebug( - "Pruned {count} expired GitHub client(s) from cache that haven't been used in {purgeAfterHours} days.", + "Pruned {count} expired GitHub client(s) from cache that haven't been used in {purgeAfterHours} hours.", purgeCount, - ClientCacheDays); + ClientCacheHours); } var rateLimitInfo = client.GetLastApiInfo()?.RateLimit;