コード例 #1
0
        public IEnumerable <AttachmentInformation> GetAttachmentsAfter(Guid etag, int take, long maxTotalSize)
        {
            Api.JetSetCurrentIndex(session, Files, "by_etag");
            Api.MakeKey(session, Files, etag.TransformToValueForEsentSorting(), MakeKeyGrbit.NewKey);
            if (Api.TrySeek(session, Files, SeekGrbit.SeekGT) == false)
            {
                return(Enumerable.Empty <AttachmentInformation>());
            }

            var optimizer = new OptimizedIndexReader(Session, Files, take);

            do
            {
                optimizer.Add();
            } while (Api.TryMoveNext(session, Files) && optimizer.Count < take);

            long totalSize = 0;

            return(optimizer
                   .Where(_ => totalSize <= maxTotalSize)
                   .Select(o => ReadCurrentAttachmentInformation())
                   .Select(x =>
            {
                totalSize += x.Size;
                return x;
            }));
        }
コード例 #2
0
ファイル: MappedResults.cs プロジェクト: spacedoom/ravendb
        public IEnumerable <RavenJObject> GetMappedResults(params GetMappedResultsParams[] getMappedResultsParams)
        {
            var optimizedIndexReader = new OptimizedIndexReader <GetMappedResultsParams>(Session, MappedResults, getMappedResultsParams.Length);

            Api.JetSetCurrentIndex(session, MappedResults, "by_reduce_key_and_view_hashed");

            foreach (var item in getMappedResultsParams)
            {
                Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
                if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekEQ) == false)
                {
                    continue;
                }

                Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
                Api.JetSetIndexRange(session, MappedResults, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive);
                do
                {
                    optimizedIndexReader.Add(item);
                } while (Api.TryMoveNext(session, MappedResults));
            }

            return(optimizedIndexReader
                   .Where(item =>
            {
                // we need to check that we don't have hash collisions
                var currentReduceKey = Api.RetrieveColumnAsString(session, MappedResults,
                                                                  tableColumnsCache.MappedResultsColumns["reduce_key"]);
                if (currentReduceKey != item.ReduceKey)
                {
                    return false;
                }

                var currentView = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"]);

                return currentView == item.View;
            })
                   .Select(item =>
            {
                using (var stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
                {
                    return stream.ToJObject();
                }
            }));
        }