public void Should_cache_metadata_of_queries_without_parameters() { var cache = new QueryMetadataCache(); Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var metadataHash, out var metadata)); Assert.NotEqual((ulong)0, metadataHash); cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, metadataHash), "test"); Assert.True(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out metadataHash, out metadata)); }
public static unsafe (FacetQueryServerSide FacetQuery, long?FacetsEtag) Create(BlittableJsonReaderObject json, JsonOperationContext context, QueryMetadataCache cache) { var result = JsonDeserializationServer.FacetQuery(json); if (result.PageSize == 0 && json.TryGet(nameof(PageSize), out int _) == false) { result.PageSize = int.MaxValue; } if (string.IsNullOrWhiteSpace(result.Query)) { throw new InvalidOperationException($"Facet query does not contain '{nameof(Query)}' field."); } long?facetsEtag = null; if (json.TryGet(nameof(Facets), out BlittableJsonReaderArray facetsArray) && facetsArray != null) { facetsEtag = Hashing.XXHash32.Calculate(facetsArray.Parent.BasePointer, facetsArray.Parent.Size); } result.Metadata = cache.TryGetMetadata(result, context, out var metadataHash, out var metadata) ? metadata : new QueryMetadata(result.Query, result.QueryParameters, metadataHash); return(result, facetsEtag); }
public void Should_not_cache_query_metadata_if_addSpatialProperties_is_set_to_true() { var cache = new QueryMetadataCache(); Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var originalMetadataHash, out _)); Assert.NotEqual((ulong)0, originalMetadataHash); cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, cacheKey: originalMetadataHash, addSpatialProperties: true), "test"); Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out var metadataHash, out _)); Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: true, out metadataHash, out _)); cache.MaybeAddToCache(new QueryMetadata("from Users order by Name", null, cacheKey: originalMetadataHash, addSpatialProperties: false), "test"); Assert.True(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: false, out metadataHash, out _)); Assert.False(cache.TryGetMetadata(new IndexQueryServerSide("from Users order by Name"), addSpatialProperties: true, out metadataHash, out _)); }