Skip to content

Commit

Permalink
Merge #4049 De-over-parallelize Versions tab
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Mar 3, 2024
2 parents 3b16d38 + f5fa504 commit fb53afb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- [Core] Only auto-delete manually installed DLLs if also replacing them (#4024 by: HebaruSan)
- [Multiple] Show repo ETag and parsing errors in Failed Downloads (#4030 by: HebaruSan)
- [Multiple] Properly clear AD upgrades from changeset (#4037 by: HebaruSan)
- [Multiple] De-over-parallelize Versions tab (#4049 by: HebaruSan)

### Internal

Expand Down
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

0 comments on commit fb53afb

Please sign in to comment.