private RealtimeQueryResult PurgeCompleted(IEnumerable <ResultEntry> entries, double queryLength, double queryOffset) { var set = new HashSet <string>(entries.Select(_ => _.Track.Id)); foreach (var entry in trackEntries.Where(_ => !set.Contains(_.Key))) { var old = entry.Value; var updated = new ResultEntry(old.Track, old.Score, old.MatchedAt, new Coverage(old.Coverage.BestPath, old.Coverage.QueryLength + queryLength + queryOffset, old.Coverage.TrackLength, old.Coverage.FingerprintLength, old.Coverage.PermittedGap)); trackEntries.TryUpdate(entry.Key, updated, old); } var completed = new List <ResultEntry>(); var cantWaitAnymore = new HashSet <ResultEntry>(); foreach (KeyValuePair <string, ResultEntry> pair in trackEntries) { if (!completionStrategy.CanContinueInNextQuery(pair.Value) && trackEntries.TryRemove(pair.Key, out var entry)) { // can't continue in the next query if (realtimeResultEntryFilter.Pass(entry, false)) { // passed entry filter completed.Add(entry); } else { // did not pass filter cantWaitAnymore.Add(entry); } } else if (realtimeResultEntryFilter.Pass(pair.Value, true) && trackEntries.TryRemove(pair.Key, out _)) { // can continue, but realtime result entry filter takes precedence completed.Add(pair.Value); } } return(new RealtimeQueryResult(Sorted(completed), Sorted(cantWaitAnymore))); }
public void MissingResultEntryCannotContinue() { Assert.IsFalse(strategy.CanContinueInNextQuery(null)); }