fix: avoid potential IndexOutOfRangeException in Models.User

This commit is contained in:
Gadfly 2024-05-11 17:00:35 +08:00
parent 73ee0ae2cd
commit 3b166a5c22

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>();
} }
} }