| 1 | using AgentForge.Services; |
| 2 | |
| 3 | namespace AgentForge.Plugin.Grouping.Repositories; |
| 4 | |
| 5 | internal sealed class ForgeCatalogGitMetadata |
| 6 | { |
| 7 | private readonly GitRepoService _git; |
| 8 | private readonly Dictionary<string, (DateTimeOffset FetchedAt, DateTimeOffset? CommitAt)> _cache = new(StringComparer.OrdinalIgnoreCase); |
| 9 | private static readonly TimeSpan Ttl = TimeSpan.FromMinutes(10); |
| 10 | |
| 11 | internal ForgeCatalogGitMetadata(GitRepoService git) => _git = git; |
| 12 | |
| 13 | internal DateTimeOffset? GetLastCommitAt(string repoFullName) |
| 14 | { |
| 15 | var now = DateTimeOffset.UtcNow; |
| 16 | if (_cache.TryGetValue(repoFullName, out var cached) && now - cached.FetchedAt < Ttl) |
| 17 | return cached.CommitAt; |
| 18 | |
| 19 | DateTimeOffset? commitAt; |
| 20 | try |
| 21 | { |
| 22 | commitAt = _git.GetLatestCommitDate(repoFullName); |
| 23 | } |
| 24 | catch |
| 25 | { |
| 26 | commitAt = null; |
| 27 | } |
| 28 | |
| 29 | _cache[repoFullName] = (now, commitAt); |
| 30 | return commitAt; |
| 31 | } |
| 32 | } |
| 33 | |
View only · write via MCP/CIDE