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;
}
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) {
confirmations.ExceptWith(ignoredConfirmations);

View file

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

View file

@ -88,7 +88,7 @@ namespace ArchiSteamFarm {
internal readonly byte MaxTradeHoldDuration = 15;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly EOptimizationMode OptimizationMode = EOptimizationMode.Balanced;
internal readonly EOptimizationMode OptimizationMode = EOptimizationMode.MaxPerformance;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly bool Statistics = true;
@ -171,9 +171,7 @@ namespace ArchiSteamFarm {
return null;
}
[SuppressMessage("ReSharper", "UnusedMember.Global")]
internal enum EOptimizationMode : byte {
Balanced,
MaxPerformance,
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) {
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")]
[JsonProperty(Required = Required.DisallowNull)]
public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.Balanced;
public EOptimizationMode OptimizationMode { get; set; } = EOptimizationMode.MaxPerformance;
[JsonProperty(Required = Required.DisallowNull)]
public bool Statistics { get; set; } = true;
@ -211,7 +211,6 @@ namespace ConfigGenerator {
}
internal enum EOptimizationMode : byte {
Balanced,
MaxPerformance,
MinMemoryUsage
}