コード例 #1
0
        public async Task <PopularityTransferData> GetPopularityTransfersAsync()
        {
            return(await RetrySqlAsync(async() =>
            {
                var stopwatch = Stopwatch.StartNew();
                var output = new PopularityTransferData();
                using (var connection = await _connectionFactory.OpenAsync())
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = GetPopularityTransfersSql;
                        command.CommandTimeout = SqlCommandTimeoutSeconds;
                        command.Parameters.Add(GetPopularityTransfersSkipParameter, SqlDbType.Int);
                        command.Parameters.AddWithValue(GetPopularityTransfersTakeParameter, GetPopularityTransfersPageSize);

                        // Load popularity transfers by paging through the database.
                        // We continue paging until we receive fewer results than the page size.
                        int currentPageResults;
                        int totalResults = 0;
                        do
                        {
                            command.Parameters[GetPopularityTransfersSkipParameter].Value = totalResults;

                            using (var reader = await command.ExecuteReaderAsync())
                            {
                                currentPageResults = 0;

                                while (await reader.ReadAsync())
                                {
                                    currentPageResults++;

                                    var fromId = reader.GetString(0);
                                    var toId = reader.GetString(1);

                                    output.AddTransfer(fromId, toId);
                                }
                            }

                            totalResults += currentPageResults;
                        }while (currentPageResults == GetPopularityTransfersPageSize);

                        stopwatch.Stop();
                        _telemetryService.TrackReadLatestPopularityTransfersFromDatabase(output.Count, stopwatch.Elapsed);

                        return output;
                    }
            }));
        }