Limit resource center queries to 50 maps at a time.
This commit is contained in:
@@ -159,48 +159,55 @@ namespace OpenRA
|
|||||||
yield return new Map(modData, mapPackage);
|
yield return new Map(modData, mapPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueryRemoteMapDetails(string repositoryUrl, IEnumerable<string> uids, Action<MapPreview> mapDetailsReceived = null, Action queryFailed = null)
|
public void QueryRemoteMapDetails(string repositoryUrl, IEnumerable<string> uids, Action<MapPreview> mapDetailsReceived = null, Action<MapPreview> mapQueryFailed = null)
|
||||||
{
|
{
|
||||||
var maps = uids.Distinct()
|
var queryUids = uids.Distinct()
|
||||||
.Where(uid => uid != null)
|
.Where(uid => uid != null)
|
||||||
.Select(uid => previews[uid])
|
.Select(uid => previews[uid])
|
||||||
.Where(p => p.Status == MapStatus.Unavailable)
|
.Where(p => p.Status == MapStatus.Unavailable)
|
||||||
.ToDictionary(p => p.Uid, p => p);
|
.Select(p => p.Uid)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (!maps.Any())
|
foreach (var uid in queryUids)
|
||||||
return;
|
previews[uid].UpdateRemoteSearch(MapStatus.Searching, null);
|
||||||
|
|
||||||
foreach (var p in maps.Values)
|
|
||||||
p.UpdateRemoteSearch(MapStatus.Searching, null);
|
|
||||||
|
|
||||||
var url = repositoryUrl + "hash/" + string.Join(",", maps.Keys) + "/yaml";
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var client = HttpClientFactory.Create();
|
var client = HttpClientFactory.Create();
|
||||||
|
|
||||||
|
// Limit each query to 50 maps at a time to avoid request size limits
|
||||||
|
for (var i = 0; i < queryUids.Count; i += 50)
|
||||||
|
{
|
||||||
|
var batchUids = queryUids.Skip(i).Take(50).ToList();
|
||||||
|
var url = repositoryUrl + "hash/" + string.Join(",", batchUids) + "/yaml";
|
||||||
|
try
|
||||||
|
{
|
||||||
var httpResponseMessage = await client.GetAsync(url);
|
var httpResponseMessage = await client.GetAsync(url);
|
||||||
var result = await httpResponseMessage.Content.ReadAsStringAsync();
|
var result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
var yaml = MiniYaml.FromString(result);
|
var yaml = MiniYaml.FromString(result);
|
||||||
foreach (var kv in yaml)
|
foreach (var kv in yaml)
|
||||||
maps[kv.Key].UpdateRemoteSearch(MapStatus.DownloadAvailable, kv.Value, mapDetailsReceived);
|
previews[kv.Key].UpdateRemoteSearch(MapStatus.DownloadAvailable, kv.Value, mapDetailsReceived);
|
||||||
|
|
||||||
foreach (var map in maps)
|
foreach (var uid in batchUids)
|
||||||
if (map.Value.Status != MapStatus.DownloadAvailable)
|
{
|
||||||
map.Value.UpdateRemoteSearch(MapStatus.Unavailable, null);
|
var p = previews[uid];
|
||||||
|
if (p.Status != MapStatus.DownloadAvailable)
|
||||||
|
p.UpdateRemoteSearch(MapStatus.Unavailable, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Write("debug", "Remote map query failed with error: {0}", e);
|
Log.Write("debug", "Remote map query failed with error: {0}", e);
|
||||||
Log.Write("debug", "URL was: {0}", url);
|
Log.Write("debug", "URL was: {0}", url);
|
||||||
|
|
||||||
foreach (var p in maps.Values)
|
foreach (var uid in batchUids)
|
||||||
|
{
|
||||||
|
var p = previews[uid];
|
||||||
p.UpdateRemoteSearch(MapStatus.Unavailable, null);
|
p.UpdateRemoteSearch(MapStatus.Unavailable, null);
|
||||||
|
mapQueryFailed?.Invoke(p);
|
||||||
queryFailed?.Invoke();
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -516,7 +516,14 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
{
|
{
|
||||||
server.SendOrderTo(conn, "Message", "Searching for map on the Resource Center...");
|
server.SendOrderTo(conn, "Message", "Searching for map on the Resource Center...");
|
||||||
var mapRepository = server.ModData.Manifest.Get<WebServices>().MapRepository;
|
var mapRepository = server.ModData.Manifest.Get<WebServices>().MapRepository;
|
||||||
server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, selectMap, queryFailed);
|
var reported = false;
|
||||||
|
server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, selectMap, _ =>
|
||||||
|
{
|
||||||
|
if (!reported)
|
||||||
|
queryFailed();
|
||||||
|
|
||||||
|
reported = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
queryFailed();
|
queryFailed();
|
||||||
|
|||||||
Reference in New Issue
Block a user