Esempio n. 1
0
        public Task Stats()
        {
            var name = GetStringQueryString("name", required: false);

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    IndexStats[] indexStats;
                    using (context.OpenReadTransaction())
                    {
                        if (string.IsNullOrEmpty(name))
                        {
                            indexStats = Database.IndexStore
                                         .GetIndexes()
                                         .OrderBy(x => x.Name)
                                         .Select(x => x.GetStats(calculateLag: true, calculateStaleness: true, documentsContext: context))
                                         .ToArray();
                        }
                        else
                        {
                            var index = Database.IndexStore.GetIndex(name);
                            if (index == null)
                            {
                                throw new InvalidOperationException("There is not index with name: " + name);
                            }

                            indexStats = new[] { index.GetStats(calculateLag: true, calculateStaleness: true, documentsContext: context) };
                        }
                    }

                    writer.WriteStartArray();
                    var first = true;
                    foreach (var stats in indexStats)
                    {
                        if (first == false)
                        {
                            writer.WriteComma();
                        }

                        first = false;
                        writer.WriteIndexStats(context, stats);
                    }

                    writer.WriteEndArray();
                }

            return(Task.CompletedTask);
        }