mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 18:37:22 +01:00
shuffle cdn shard configs to allow for multiple file shards to handle one file, randomly distributing
This commit is contained in:
parent
9a9beb9a65
commit
f8c9d1e64f
2 changed files with 19 additions and 0 deletions
|
|
@ -59,6 +59,7 @@ public partial class MareHub
|
|||
{
|
||||
var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
shardConfig.Shuffle();
|
||||
var matchedShardConfig = shardConfig.Find(f => f.FileMatchRegex.Match(file.Hash).Success);
|
||||
var baseUrl = matchedShardConfig?.CdnFullUrl ?? _mainCdnFullUrl;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,3 +29,21 @@ public static class StringUtils
|
|||
return BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(input))).Replace("-", "", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListUtils
|
||||
{
|
||||
private static Random rng = new();
|
||||
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
{
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = rng.Next(n + 1);
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue