Пример #1
0
        private async Task <List <TEntry> > ReadWithUnknownEnd(TKey id, TableQuery <TsdbTableEntity> query, ITable currentTable, Sort sort, int?count)
        {
            List <List <TEntry> > entries = new List <List <TEntry> >();

            var  maxTableMisses  = _tableProvider.GetMaxTableMisses(id);
            int  tableMisses     = 0;
            bool queryMoreTables = true;

            while (queryMoreTables)
            {
                var foundEntries = await ReadInternal(query, currentTable, sort, count).ConfigureAwait(false);

                entries.Add(foundEntries);

                // if we have not found everything
                if (!count.HasValue || entries.Sum(x => x.Count) < count)
                {
                    // determine if we should try more
                    if (foundEntries.Count > 0)
                    {
                        tableMisses = 0;

                        // we want to keep trying as we found something in this table (likely there MAY be more in previous table)
                        currentTable = _tableProvider.GetPreviousTable(currentTable);
                    }
                    else
                    {
                        // we did NOT find anything in this table
                        if (tableMisses <= maxTableMisses)
                        {
                            // ONLY look in previous table if this was our FIRST iteration
                            currentTable = _tableProvider.GetPreviousTable(currentTable);
                            tableMisses++;
                        }
                        else
                        {
                            queryMoreTables = false;
                        }
                    }
                }
                else
                {
                    // if we have found everything
                    queryMoreTables = false;
                }
            }

            if (sort == Sort.Ascending)
            {
                entries.Reverse();
            }

            return(entries.SelectMany(x => x).ToList());
        }