Esempio n. 1
0
    public async Task UpdateCachedRecordAsync(MapRecordCache newCache)
    {
        const string query = @"INSERT INTO `worldRecordCache` VALUES (@MapId, @ClassId, @ZoneType, @ZoneId, @CurrentRecordDuration, @OldRecordDuration) ON DUPLICATE KEY UPDATE `currentWrDuration`=@CurrentRecordDuration, `oldWrDuration`=@OldRecordDuration";

        var param = new
        {
            newCache.MapId,
            newCache.ClassId,
            newCache.ZoneType,
            newCache.ZoneId,
            CurrentRecordDuration = newCache.CurrentWrDuration,
            OldRecordDuration     = newCache.OldWrDuration
        };

        await ExecuteAsync(query, param).ConfigureAwait(false);
    }
Esempio n. 2
0
    public async Task <MapRecordCache> UpdateCachedWrDataAsync(MapRecordCache?cached, CachedTempusRecordBase map)
    {
        if (map is null)
        {
            throw new ArgumentNullException(nameof(map));
        }

        var tempNewCache = cached;

        // Check for no data
        if (cached == null || !cached.CurrentWrDuration.HasValue && !cached.OldWrDuration.HasValue)
        {
            // No data
            tempNewCache = new MapRecordCache
            {
                MapId             = map.MapInfo.Id,
                CurrentWrDuration = map.RecordInfo.Duration,
                ClassId           = map.RecordInfo.Class,
                ZoneType          = map.ZoneInfo.Type,
                OldWrDuration     = null,
                ZoneId            = map.ZoneInfo.Zoneindex
            };

            await _mySql.UpdateCachedRecordAsync(tempNewCache).ConfigureAwait(false);
        }
        // Check if the cached wr duration is slower to the new record
        else if (cached.CurrentWrDuration.HasValue &&
                 cached.CurrentWrDuration.Value.SlowerThan(map.RecordInfo.Duration))
        {
            tempNewCache = new MapRecordCache
            {
                MapId             = map.MapInfo.Id,
                CurrentWrDuration = map.RecordInfo.Duration,
                OldWrDuration     = cached.CurrentWrDuration,
                ClassId           = map.RecordInfo.Class,
                ZoneType          = map.ZoneInfo.Type,
                ZoneId            = map.ZoneInfo.Zoneindex
            };

            await _mySql.UpdateCachedRecordAsync(tempNewCache).ConfigureAwait(false);
        }

        return(tempNewCache);
    }