Exemplo n.º 1
0
        public async Task <IResultList <Topic> > QueryAsync(string appId, TopicQuery query, CancellationToken ct)
        {
            var filters = new List <FilterDefinition <MongoDbTopic> >
            {
                Filter.Eq(x => x.Doc.AppId, appId)
            };

            if (!string.IsNullOrWhiteSpace(query.Query))
            {
                var regex = new BsonRegularExpression(query.Query, "i");

                filters.Add(Filter.Regex(x => x.Doc.Path, regex));
            }

            var filter = Filter.And(filters);

            var resultItems = await Collection.Find(filter).SortByDescending(x => x.Doc.LastUpdate).ToListAsync(query, ct);

            var resultTotal = (long)resultItems.Count;

            if (query.ShouldQueryTotal(resultItems))
            {
                resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
            }

            return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToTopic())));
        }
Exemplo n.º 2
0
        public async Task <IResultList <Topic> > QueryAsync(string appId, TopicQuery query,
                                                            CancellationToken ct = default)
        {
            using (var activity = Telemetry.Activities.StartActivity("MongoDbTopicRepository/QueryAsync"))
            {
                var filter = BuildFilter(appId, query);

                var resultItems = await Collection.Find(filter).SortByDescending(x => x.Doc.LastUpdate).ToListAsync(query, ct);

                var resultTotal = (long)resultItems.Count;

                if (query.ShouldQueryTotal(resultItems))
                {
                    resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
                }

                activity?.SetTag("numResults", resultItems.Count);
                activity?.SetTag("numTotal", resultTotal);

                return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToTopic())));
            }
        }