Improved performance of GetPmcNicknameOfMaxLength by using any()

This commit is contained in:
Chomp
2025-02-24 17:43:32 +00:00
parent 2c42837c25
commit 7296ee2c0c
+3 -3
View File
@@ -188,12 +188,12 @@ public class BotHelper(
/// <param name="maxLength">Max length of name, inclusive</param>
/// <param name="side">OPTIONAL - what side PMC to get name from (usec/bear)</param>
/// <returns>name of PMC</returns>
public string GetPmcNicknameOfMaxLength(int maxLength, string side = null)
public string GetPmcNicknameOfMaxLength(int maxLength, string? side = null)
{
var randomType = side is not null ? side : _randomUtil.GetInt(0, 1) == 0 ? "usec" : "bear";
var randomType = side ?? (_randomUtil.GetInt(0, 1) == 0 ? "usec" : "bear");
var allNames = _databaseService.GetBots().Types[randomType.ToLower()].FirstNames;
var filteredNames = allNames.Where(name => name.Length <= maxLength);
if (filteredNames.Count() == 0)
if (!filteredNames.Any())
{
_logger.Warning(
$"Unable to filter: {randomType} PMC names to only those under: {maxLength}, none found that match that criteria, selecting from entire name pool instead`,\n"