Merge pull request #122 from gadfly3173/fix/dictionary-exception

fix: avoid potential IndexOutOfRangeException in Models.User
This commit is contained in:
leo 2024-05-11 17:09:26 +08:00 committed by GitHub
commit 62838e5b05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Concurrent;
namespace SourceGit.Models namespace SourceGit.Models
{ {
@ -36,11 +36,11 @@ namespace SourceGit.Models
var email = data.Substring(nameEndIdx + 1); var email = data.Substring(nameEndIdx + 1);
User user = new User() { Name = name, Email = email }; User user = new User() { Name = name, Email = email };
_caches.Add(data, user); _caches.TryAdd(data, user);
return user; return user;
} }
} }
private static Dictionary<string, User> _caches = new Dictionary<string, User>(); private static ConcurrentDictionary<string, User> _caches = new ConcurrentDictionary<string, User>();
} }
} }