// load documents from document loader protected IEnumerable <BsonDocument> LoadDocument(IEnumerable <IndexNode> nodes) { foreach (var node in nodes) { yield return(_lookup.Load(node)); // check if transaction all full of pages to clear before continue _transaction.Safepoint(); } }
public IEnumerator <BsonDocument> GetEnumerator() { // https://stackoverflow.com/a/34633464/3286260 // the index of the current item in the cache. var index = 0; #if DEBUG if (_cache.Count > 0) { LOG($"document group cache request (key: {_key}, size: {_cache.Count})", "GROUPBY"); } #endif // enumerate the _cache first for (; index < _cache.Count; index++) { var rawId = _cache[index]; yield return(_lookup.Load(rawId)); } // continue enumeration of the original _enumerator, until it is finished. // this adds items to the cache and increment for (; _enumerator != null && _enumerator.MoveNext(); index++) { var current = _enumerator.Current; ENSURE(current.RawId.IsEmpty == false, "rawId must have a valid value"); _cache.Add(current.RawId); yield return(current); } if (_enumerator != null) { _enumerator.Dispose(); _enumerator = null; } // other users of the same instance of DocumentEnumerable // can add more items to the cache, so we need to enumerate them as well for (; index < _cache.Count; index++) { var rawId = _cache[index]; yield return(_lookup.Load(rawId)); } }