Пример #1
0
        private async Task UpdateMmrSnapshots(int season, string classification, MmrSnapshot mmrSnapshot)
        {
            _mmrDataStore.AddSnapshot(season, classification, mmrSnapshot);

            _logger.LogInformation("Updating database with newest snapshot");

            var sw = Stopwatch.StartNew();
            await _databaseService.AddSnapshot(mmrSnapshot, _stoppingToken, season);

            sw.Stop();
            _logger.LogInformation("Updated database in {time}ms", sw.ElapsedMilliseconds);
        }
Пример #2
0
        /// <summary>
        /// Adds a snapshot to the list.
        /// </summary>
        public async Task <int> AddSnapshot(MmrSnapshot snapshot, CancellationToken token, int season)
        {
            // Making connection with Npgsql provider
            using NpgsqlConnection conn = new NpgsqlConnection(_connectionString);
            await conn.OpenAsync();

            string query = $"CALL {_schema}.insert_snapshot(@date::date, @snapshotJson, @season);";

            using NpgsqlCommand command = new NpgsqlCommand(query, conn);
            command.Parameters.Add(new NpgsqlParameter("date", snapshot.SnapshotTime));
            command.Parameters.Add(new NpgsqlParameter("snapshotJson", JsonSerializer.Serialize(snapshot.MmrList)));
            command.Parameters.Add(new NpgsqlParameter("season", season));

            var result = await command.ExecuteNonQueryAsync(token);

            return(result);
        }