Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Given the data, and high chance of duplicates within each thread (and low chance of duplicates between threads) I decided to go with the following solution, it allows each thread to perform its stuff without impediment from locks and does a little filtering at the end on the caller thread to ensure the filtering is done correctly. </p> <p>It also has the added benefit that the order in which the objects are returned from the service calls (date order) is maintained across threads so no need to sort it at the end.</p> <pre><code>public IEnumerable&lt;Stuff&gt; GetStuffs(DateTime startDate, DateTime endDate) { if (startDate &gt;= endDate) throw new ArgumentException("startDate must be before endDate", "startDate"); IDateRange dateRange = new DateRange(startDate, endDate); IDateRange[] dateRanges = _dateRangeSplitter.DivideRange(dateRange, TimeSpan.FromDays(1)).ToArray(); IEnumerable&lt;Stuff&gt;[] resultCollections = new IEnumerable&lt;Stuff&gt;[dateRanges.Length]; _parallel.For(0, dateRanges.Length, i =&gt; { IDateRange splitRange = dateRanges[i]; IEnumerable&lt;Stuff&gt; stuffs = GetMarketStuffs(splitRange); resultCollections[i] = stuffs; }); Stuff[] marketStuffs = resultCollections.SelectMany(ef =&gt; ef).Distinct(ef =&gt; ef.EventId).ToArray(); return marketStuffs; } private IEnumerable&lt;Stuff&gt; GetMarketStuffs(IDateRange splitRange) { IList&lt;Stuff&gt; stuffs = new List&lt;Stuff&gt;(); HashSet&lt;int&gt; uniqueStuffIds = new HashSet&lt;int&gt;(); string marketStuffString = _slowStuffStringProvider.GetMarketStuffs(splitRange.Start, splitRange.End); IEnumerable&lt;ParsedStuff&gt; rows = _stuffParser.ParseStuffString(marketStuffString); foreach (ParsedStuff parsedStuff in rows) { if (!uniqueStuffIds.Add(parsedStuff.EventId)) { continue; } stuffs.Add(new Stuff(parsedStuff)); } return stuffs; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload