-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #3917 Parallelize for performance, relationship resolver improv…
…ements
- Loading branch information
Showing
68 changed files
with
2,037 additions
and
1,679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Collections.Concurrent; | ||
|
||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
using CKAN.Extensions; | ||
|
||
namespace CKAN | ||
{ | ||
/// <summary> | ||
/// A converter that loads a dictionary in parallel, | ||
/// use with large collections of complex objects for a speed boost | ||
/// </summary> | ||
public class JsonParallelDictionaryConverter<V> : JsonConverter | ||
{ | ||
public override object ReadJson(JsonReader reader, | ||
Type objectType, | ||
object existingValue, | ||
JsonSerializer serializer) | ||
=> ParseWithProgress(JObject.Load(reader) | ||
.Properties() | ||
.ToArray(), | ||
serializer); | ||
|
||
private object ParseWithProgress(JProperty[] properties, | ||
JsonSerializer serializer) | ||
=> Partitioner.Create(properties, true) | ||
.AsParallel() | ||
.WithMergeOptions(ParallelMergeOptions.NotBuffered) | ||
.Select(prop => new KeyValuePair<string, V>( | ||
prop.Name, | ||
prop.Value.ToObject<V>())) | ||
.WithProgress(properties.Length, | ||
serializer.Context.Context as IProgress<int>) | ||
.ToDictionary(); | ||
|
||
public override bool CanWrite => false; | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
// Only convert when we're an explicit attribute | ||
public override bool CanConvert(Type object_type) => false; | ||
} | ||
} |
Oops, something went wrong.