- fix: Server entries cache key to string

This commit is contained in:
2025-01-31 22:55:01 +03:00
parent 329ec268cc
commit 9eff84ddf8

View File

@@ -140,7 +140,7 @@ public class ServerViewContainer(
ViewHelperService viewHelperService ViewHelperService viewHelperService
) )
{ {
private readonly Dictionary<RobustUrl, ServerEntryModelView> _entries = new(); private readonly Dictionary<string, ServerEntryModelView> _entries = new();
public void Clear() public void Clear()
{ {
@@ -149,10 +149,15 @@ public class ServerViewContainer(
public async Task<ServerEntryModelView> Get(RobustUrl url, ServerStatus? serverStatus = null) public async Task<ServerEntryModelView> Get(RobustUrl url, ServerStatus? serverStatus = null)
{ {
if (_entries.TryGetValue(url, out var entry)) lock (_entries)
{ {
return entry; if (_entries.TryGetValue(url.ToString(), out var entry1))
{
return entry1;
}
} }
Console.WriteLine("Creating new instance... " + url.ToString() + _entries.Keys.ToList().Contains(url.ToString()));
try try
{ {
@@ -165,13 +170,21 @@ public class ServerViewContainer(
-1); -1);
} }
entry = viewHelperService.GetViewModel<ServerEntryModelView>().WithData(url, serverStatus); var entry = viewHelperService.GetViewModel<ServerEntryModelView>().WithData(url, serverStatus);
entry.OnFavoriteToggle += () => entry.OnFavoriteToggle += () =>
{ {
if (entry.IsFavorite) serverListViewModel.RemoveFavorite(entry); if (entry.IsFavorite) serverListViewModel.RemoveFavorite(entry);
else serverListViewModel.AddFavorite(entry); else serverListViewModel.AddFavorite(entry);
}; };
_entries.Add(url, entry);
lock (_entries)
{
if (_entries.TryGetValue(url.ToString(), out var entry1))
{
return entry1;
}
_entries.Add(url.ToString(), entry);
}
return entry; return entry;
} }