ASF doesn't really make use of Balanced profile (as opposed to ArchiBoT), remove it leaving only MaxPerformance/MinMemoryUsage
This commit is contained in:
JustArchi
2017-01-30 22:42:05 +01:00
parent 8691050ed7
commit e4f4859eb4
5 changed files with 77 additions and 17 deletions

View File

@@ -277,9 +277,23 @@ namespace ArchiSteamFarm {
continue; continue;
} }
Steam.ConfirmationDetails[] detailsResults = await Task.WhenAll(confirmations.Select(BotDatabase.MobileAuthenticator.GetConfirmationDetails)).ConfigureAwait(false); ICollection<Steam.ConfirmationDetails> results;
IEnumerable<Task<Steam.ConfirmationDetails>> tasks = confirmations.Select(BotDatabase.MobileAuthenticator.GetConfirmationDetails);
HashSet<MobileAuthenticator.Confirmation> ignoredConfirmations = new HashSet<MobileAuthenticator.Confirmation>(detailsResults.Where(details => (details != null) && (((acceptedSteamID != 0) && (details.OtherSteamID64 != 0) && (acceptedSteamID != details.OtherSteamID64)) || ((acceptedTradeIDs != null) && (details.TradeOfferID != 0) && !acceptedTradeIDs.Contains(details.TradeOfferID)))).Select(details => details.Confirmation)); switch (Program.GlobalConfig.OptimizationMode) {
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
results = new List<Steam.ConfirmationDetails>(confirmations.Count);
foreach (Task<Steam.ConfirmationDetails> task in tasks) {
results.Add(await task.ConfigureAwait(false));
}
break;
default:
results = await Task.WhenAll(tasks).ConfigureAwait(false);
break;
}
HashSet<MobileAuthenticator.Confirmation> ignoredConfirmations = new HashSet<MobileAuthenticator.Confirmation>(results.Where(details => (details != null) && (((acceptedSteamID != 0) && (details.OtherSteamID64 != 0) && (acceptedSteamID != details.OtherSteamID64)) || ((acceptedTradeIDs != null) && (details.TradeOfferID != 0) && !acceptedTradeIDs.Contains(details.TradeOfferID)))).Select(details => details.Confirmation));
if (ignoredConfirmations.Count > 0) { if (ignoredConfirmations.Count > 0) {
confirmations.ExceptWith(ignoredConfirmations); confirmations.ExceptWith(ignoredConfirmations);

View File

@@ -320,7 +320,7 @@ namespace ArchiSteamFarm {
return; return;
} }
HashSet<Task> extraTasks = new HashSet<Task>(); HashSet<Task> backgroundTasks = new HashSet<Task>();
foreach (HtmlNode htmlNode in htmlNodes) { foreach (HtmlNode htmlNode in htmlNodes) {
HtmlNode appIDNode = htmlNode.SelectSingleNode(".//div[@class='card_drop_info_dialog']"); HtmlNode appIDNode = htmlNode.SelectSingleNode(".//div[@class='card_drop_info_dialog']");
@@ -488,12 +488,22 @@ namespace ArchiSteamFarm {
if (cardsRemaining > 0) { if (cardsRemaining > 0) {
GamesToFarm.Add(new Game(appID, name, hours, cardsRemaining)); GamesToFarm.Add(new Game(appID, name, hours, cardsRemaining));
} else { } else {
extraTasks.Add(CheckGame(appID, name, hours)); Task task = CheckGame(appID, name, hours);
switch (Program.GlobalConfig.OptimizationMode) {
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
await task.ConfigureAwait(false);
break;
default:
backgroundTasks.Add(task);
break;
}
} }
} }
// If we have any pending tasks, wait for them // If we have any background tasks, wait for them
await Task.WhenAll(extraTasks).ConfigureAwait(false); if (backgroundTasks.Count > 0) {
await Task.WhenAll(backgroundTasks).ConfigureAwait(false);
}
} }
private async Task CheckPage(byte page) { private async Task CheckPage(byte page) {
@@ -689,18 +699,43 @@ namespace ArchiSteamFarm {
GamesToFarm.ClearAndTrim(); GamesToFarm.ClearAndTrim();
List<Task> tasks = new List<Task>(maxPages - 1) { CheckPage(htmlDocument) }; List<Task> backgroundTasks = new List<Task>();
Task task = CheckPage(htmlDocument);
switch (Program.GlobalConfig.OptimizationMode) {
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
await task.ConfigureAwait(false);
break;
default:
backgroundTasks.Add(task);
break;
}
if (maxPages > 1) { if (maxPages > 1) {
Bot.ArchiLogger.LogGenericInfo(Strings.CheckingOtherBadgePages); Bot.ArchiLogger.LogGenericInfo(Strings.CheckingOtherBadgePages);
for (byte page = 2; page <= maxPages; page++) { switch (Program.GlobalConfig.OptimizationMode) {
byte currentPage = page; // We need a copy of variable being passed when in for loops, as loop will proceed before task is launched case GlobalConfig.EOptimizationMode.MinMemoryUsage:
tasks.Add(CheckPage(currentPage)); for (byte page = 2; page <= maxPages; page++) {
await CheckPage(page).ConfigureAwait(false);
}
break;
default:
for (byte page = 2; page <= maxPages; page++) {
// We need a copy of variable being passed when in for loops, as loop will proceed before our task is launched
byte currentPage = page;
backgroundTasks.Add(CheckPage(currentPage));
}
break;
} }
} }
await Task.WhenAll(tasks).ConfigureAwait(false); if (backgroundTasks.Count > 0) {
await Task.WhenAll(backgroundTasks).ConfigureAwait(false);
}
SortGamesToFarm(); SortGamesToFarm();
return GamesToFarm.Count > 0; return GamesToFarm.Count > 0;
} }

View File

@@ -88,7 +88,7 @@ namespace ArchiSteamFarm {
internal readonly byte MaxTradeHoldDuration = 15; internal readonly byte MaxTradeHoldDuration = 15;
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal readonly EOptimizationMode OptimizationMode = EOptimizationMode.Balanced; internal readonly EOptimizationMode OptimizationMode = EOptimizationMode.MaxPerformance;
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
internal readonly bool Statistics = true; internal readonly bool Statistics = true;
@@ -171,9 +171,7 @@ namespace ArchiSteamFarm {
return null; return null;
} }
[SuppressMessage("ReSharper", "UnusedMember.Global")]
internal enum EOptimizationMode : byte { internal enum EOptimizationMode : byte {
Balanced,
MaxPerformance, MaxPerformance,
MinMemoryUsage MinMemoryUsage
} }

View File

@@ -102,7 +102,21 @@ namespace ArchiSteamFarm {
} }
} }
ParseTradeResult[] results = await Task.WhenAll(tradeOffers.Select(ParseTrade)).ConfigureAwait(false); ICollection<ParseTradeResult> results;
IEnumerable<Task<ParseTradeResult>> tasks = tradeOffers.Select(ParseTrade);
switch (Program.GlobalConfig.OptimizationMode) {
case GlobalConfig.EOptimizationMode.MinMemoryUsage:
results = new List<ParseTradeResult>(tradeOffers.Count);
foreach (Task<ParseTradeResult> task in tasks) {
results.Add(await task.ConfigureAwait(false));
}
break;
default:
results = await Task.WhenAll(tasks).ConfigureAwait(false);
break;
}
if (Bot.HasMobileAuthenticator) { if (Bot.HasMobileAuthenticator) {
HashSet<ulong> acceptedWithItemLoseTradeIDs = new HashSet<ulong>(results.Where(result => (result != null) && (result.Result == ParseTradeResult.EResult.AcceptedWithItemLose)).Select(result => result.TradeID)); HashSet<ulong> acceptedWithItemLoseTradeIDs = new HashSet<ulong>(results.Where(result => (result != null) && (result.Result == ParseTradeResult.EResult.AcceptedWithItemLose)).Select(result => result.TradeID));

View File

@@ -100,7 +100,7 @@ namespace ConfigGenerator {
[LocalizedCategory("Performance")] [LocalizedCategory("Performance")]
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.Balanced; public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.MaxPerformance;
[JsonProperty(Required = Required.DisallowNull)] [JsonProperty(Required = Required.DisallowNull)]
public bool Statistics { get; set; } = true; public bool Statistics { get; set; } = true;
@@ -211,7 +211,6 @@ namespace ConfigGenerator {
} }
internal enum EOptimizationMode : byte { internal enum EOptimizationMode : byte {
Balanced,
MaxPerformance, MaxPerformance,
MinMemoryUsage MinMemoryUsage
} }