public IEnumerable <JsonDocument> GetDocumentsByReverseUpdateOrder(int start, int take) { Api.JetSetCurrentIndex(session, Documents, "by_etag"); Api.MoveAfterLast(session, Documents); if (TryMoveTableRecords(Documents, start, backward: true)) { return(Enumerable.Empty <JsonDocument>()); } if (take < 1024 * 4) { var optimizer = new OptimizedIndexReader(); while (Api.TryMovePrevious(session, Documents) && optimizer.Count < take) { optimizer.Add(Session, Documents); } return(optimizer.Select(Session, Documents, ReadCurrentDocument)); } return(GetDocumentsWithoutBuffering(take)); }
public IEnumerable <AttachmentInformation> GetAttachmentsStartingWith(string idPrefix, int start, int pageSize) { if (pageSize <= 0) { return(Enumerable.Empty <AttachmentInformation>()); } Api.JetSetCurrentIndex(session, Files, "by_name"); Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey); if (Api.TrySeek(session, Files, SeekGrbit.SeekGE) == false) { return(Enumerable.Empty <AttachmentInformation>()); } var optimizer = new OptimizedIndexReader(); do { Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit); if (Api.TrySetIndexRange(session, Files, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive) == false) { return(Enumerable.Empty <AttachmentInformation>()); } while (start > 0) { if (Api.TryMoveNext(session, Files) == false) { return(Enumerable.Empty <AttachmentInformation>()); } start--; } optimizer.Add(Session, Files); } while (Api.TryMoveNext(session, Files) && optimizer.Count < pageSize); return(optimizer.Select(Session, Files, ReadCurrentAttachmentInformation)); }
public IEnumerable<AttachmentInformation> GetAttachmentsStartingWith(string idPrefix, int start, int pageSize) { Api.JetSetCurrentIndex(session, Files, "by_name"); Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey); if (Api.TrySeek(session, Files, SeekGrbit.SeekGE) == false) return Enumerable.Empty<AttachmentInformation>(); var optimizer = new OptimizedIndexReader(Session, Files, pageSize); do { Api.MakeKey(session, Files, idPrefix, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.SubStrLimit); if (Api.TrySetIndexRange(session, Files, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive) == false) return Enumerable.Empty<AttachmentInformation>(); while (start > 0) { if (Api.TryMoveNext(session, Files) == false) return Enumerable.Empty<AttachmentInformation>(); start--; } optimizer.Add(); } while (Api.TryMoveNext(session, Files) && optimizer.Count < pageSize); return optimizer.Select(ReadCurrentAttachmentInformation); }
public IEnumerable<AttachmentInformation> GetAttachmentsAfter(Guid etag, int take) { 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); return optimizer.Select(() => new AttachmentInformation { Size = Api.RetrieveColumnSize(session, Files, tableColumnsCache.FilesColumns["data"]) ?? 0, Etag = Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]).TransfromToGuidWithProperSorting(), Key = Api.RetrieveColumnAsString(session, Files, tableColumnsCache.FilesColumns["name"], Encoding.Unicode), Metadata = RavenJObject.Parse(Api.RetrieveColumnAsString(session, Files, tableColumnsCache.FilesColumns["metadata"], Encoding.Unicode)) }); }
public IEnumerable<MappedResultInfo> GetMappedResultsReduceKeysAfter(string indexName, Guid lastReducedEtag, bool loadData, int take) { Api.JetSetCurrentIndex(session, MappedResults, "by_view_and_etag"); Api.MakeKey(session, MappedResults, indexName, Encoding.Unicode, MakeKeyGrbit.NewKey); Api.MakeKey(session, MappedResults, lastReducedEtag, MakeKeyGrbit.None); if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekLE) == false) return Enumerable.Empty<MappedResultInfo>(); var optimizer = new OptimizedIndexReader(Session, MappedResults, take); while ( optimizer.Count < take && Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"], Encoding.Unicode, RetrieveColumnGrbit.RetrieveFromIndex) == indexName) { optimizer.Add(); // the index is view ascending and etag descending // that means that we are going backward to go up if (Api.TryMovePrevious(session, MappedResults) == false) break; } return optimizer.Select(() => new MappedResultInfo { ReduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"]), Etag = new Guid(Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"])), Timestamp = Api.RetrieveColumnAsDateTime(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"]).Value, Data = loadData ? Api.RetrieveColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"]).ToJObject() : null, }); }