Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-over-parallelize Versions tab #4049

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public static Dictionary<K, V> ToDictionary<K, V>(this ParallelQuery<KeyValuePai
public static ConcurrentDictionary<K, V> ToConcurrentDictionary<K, V>(this IEnumerable<KeyValuePair<K, V>> pairs)
=> new ConcurrentDictionary<K, V>(pairs);

public static IEnumerable<T> AsParallelIf<T>(this IEnumerable<T> source,
bool parallel)
=> parallel ? source.AsParallel()
: source;

// https://stackoverflow.com/a/55591477/2422988
public static ParallelQuery<T> WithProgress<T>(this ParallelQuery<T> source,
long totalCount,
Expand Down
2 changes: 1 addition & 1 deletion Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ public bool CanInstall(List<CkanModule> toInstall,
.Where(m => m != null);
var resolver = new RelationshipResolver(toInstall, installed, opts, registry, crit);

var resolverModList = resolver.ModList().ToList();
var resolverModList = resolver.ModList(false).ToList();
if (resolverModList.Count >= toInstall.Count(m => !m.IsMetapackage))
{
// We can install with no further dependencies
Expand Down
8 changes: 4 additions & 4 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@ private bool MightBeInstallable(CkanModule module,
/// Returns a list of all modules to install to satisfy the changes required.
/// Each mod is after its dependencies and before its reverse dependencies.
/// </summary>
public IEnumerable<CkanModule> ModList()
public IEnumerable<CkanModule> ModList(bool parallel = true)
=> modlist.Values
.Distinct()
.AsParallel()
.AsParallelIf(parallel)
// Put user choices at the bottom; .OrderBy(bool) -> false first
.OrderBy(m => ReasonsFor(m).Any(r => r is SelectionReason.UserRequested))
// Put dependencies before dependers
Expand All @@ -539,8 +539,8 @@ private static bool AnyRelationship(SelectionReason r)
|| r is SelectionReason.Recommended
|| r is SelectionReason.Suggested;

private IEnumerable<T> BreadthFirstSearch<T>(IEnumerable<T> startingGroup,
Func<T, HashSet<T>, IEnumerable<T>> getNextGroup)
private static IEnumerable<T> BreadthFirstSearch<T>(IEnumerable<T> startingGroup,
Func<T, HashSet<T>, IEnumerable<T>> getNextGroup)
{
var found = startingGroup.ToHashSet();
var toSearch = new Queue<T>(found);
Expand Down
14 changes: 4 additions & 10 deletions Core/Types/CkanModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public CkanModule(
/// <summary>
/// Inflates a CKAN object from a JSON string.
/// </summary>
public CkanModule(string json, IGameComparator comparator)
public CkanModule(string json, IGameComparator comparator = null)
{
try
{
Expand All @@ -355,7 +355,7 @@ public CkanModule(string json, IGameComparator comparator)
string.Format(Properties.Resources.CkanModuleDeserialisationError, ex.Message),
ex);
}
_comparator = comparator;
_comparator = comparator ?? ServiceLocator.Container.Resolve<IGameComparator>();
CheckHealth();
CalculateSearchables();
}
Expand Down Expand Up @@ -510,18 +510,12 @@ public static string ToJson(CkanModule module)
}

/// <summary>
/// Generates a CKAN.META object from a string.
/// Generates a CkanModule object from a string.
/// Also validates that all required fields are present.
/// Throws a BadMetaDataKraken if any fields are missing.
/// </summary>
public static CkanModule FromJson(string json)
{
log.Debug("Inflating comparator object");
IGameComparator comparator = ServiceLocator.Container.Resolve<IGameComparator>();

log.Debug("Building CkanModule");
return new CkanModule(json, comparator);
}
=> new CkanModule(json);

#endregion

Expand Down
2 changes: 2 additions & 0 deletions GUI/Controls/ModInfoTabs/Versions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private void checkInstallable(ListViewItem[] items)
{
if (latestCompatible == null || item.Index < latestCompatible.Index)
{
VersionsListView.BeginUpdate();
if (latestCompatible != null)
{
// Revert color of previous best guess
Expand All @@ -250,6 +251,7 @@ private void checkInstallable(ListViewItem[] items)
latestCompatible = item;
item.BackColor = Color.Green;
item.ForeColor = Color.White;
VersionsListView.EndUpdate();
}
else
{
Expand Down
Loading