Performance improvements. Timely command almost done

This commit is contained in:
Master Kwoth
2017-10-26 11:31:44 +02:00
parent ffcaa594c9
commit 8220487672
18 changed files with 2084 additions and 23 deletions

View File

@ -30,6 +30,8 @@ namespace NadekoBot.Core.Services.Database.Models
public float Betroll67Multiplier { get; set; } = 2;
public float Betroll91Multiplier { get; set; } = 4;
public float Betroll100Multiplier { get; set; } = 10;
public int TimelyCurrency { get; set; } = 0;
public int TimelyCurrencyPeriod { get; set; } = 0;
//public HashSet<CommandCost> CommandCosts { get; set; } = new HashSet<CommandCost>();
/// <summary>

View File

@ -0,0 +1,19 @@
using NadekoBot.Common.Collections;
using System.Collections.Generic;
namespace NadekoBot.Core.Services.Database.Models
{
public class Poll
{
public ulong GuildId { get; set; }
public string Question { get; set; }
public IndexedCollection<PollAnswer> Answers { get; set; }
public HashSet<PollVote> Votes { get; set; }
}
public class PollAnswer : IIndexed
{
public int Index { get; set; }
public string Text { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Core.Services.Database.Models
{
public class PollVote
{
}
}

View File

@ -1,4 +1,5 @@
using StackExchange.Redis;
using System;
using System.Threading.Tasks;
namespace NadekoBot.Core.Services
@ -10,5 +11,6 @@ namespace NadekoBot.Core.Services
Task<(bool Success, string Data)> TryGetAnimeDataAsync(string key);
Task SetImageDataAsync(string key, byte[] data);
Task SetAnimeDataAsync(string link, string data);
TimeSpan? AddTimelyClaim(ulong id, int period);
}
}

View File

@ -1,7 +1,5 @@
using System;
using NadekoBot.Common;
using NadekoBot.Common;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Core.Services;
namespace NadekoBot.Core.Services.Impl
{
@ -28,7 +26,7 @@ namespace NadekoBot.Core.Services.Impl
{
using (var uow = _db.UnitOfWork)
{
var bc = uow.BotConfig.GetOrCreate();
var bc = uow.BotConfig.GetOrCreate(set => set);
switch (type)
{
case BotConfigEditType.CurrencyGenerationChance:

View File

@ -106,7 +106,7 @@ namespace NadekoBot.Core.Services.Impl
{
using (var uow = _db.UnitOfWork)
{
var bc = uow.BotConfig.GetOrCreate();
var bc = uow.BotConfig.GetOrCreate(set => set);
bc.Locale = ci.Name;
uow.Complete();
}

View File

@ -1,4 +1,6 @@
using StackExchange.Redis;
using NadekoBot.Extensions;
using StackExchange.Redis;
using System;
using System.Threading.Tasks;
namespace NadekoBot.Core.Services.Impl
@ -7,12 +9,14 @@ namespace NadekoBot.Core.Services.Impl
{
public ConnectionMultiplexer Redis { get; }
private readonly IDatabase _db;
private readonly string _redisKey;
public RedisCache()
public RedisCache(IBotCredentials creds)
{
Redis = ConnectionMultiplexer.Connect("127.0.0.1");
Redis.PreserveAsyncOrder = false;
_db = Redis.GetDatabase();
_redisKey = creds.RedisKey();
}
// things here so far don't need the bot id
@ -40,5 +44,21 @@ namespace NadekoBot.Core.Services.Impl
{
return _db.StringSetAsync("anime_" + key, data);
}
private readonly object timelyLock = new object();
public TimeSpan? AddTimelyClaim(ulong id, int period)
{
lock (timelyLock)
{
var time = TimeSpan.FromHours(period);
if ((bool?)_db.StringGet($"{_redisKey}_timelyclaim_{id}") == null)
{
_db.StringSet($"{_redisKey}_timelyclaim_{id}", true);
_db.KeyExpire($"{_redisKey}_timelyclaim_{id}", time);
return time;
}
return _db.KeyTimeToLive($"{_redisKey}_timelyclaim_{id}");
}
}
}
}

View File

@ -65,8 +65,8 @@ namespace NadekoBot
_log = LogManager.GetCurrentClassLogger();
TerribleElevatedPermissionCheck();
Cache = new RedisCache();
Credentials = new BotCredentials();
Cache = new RedisCache(Credentials);
_db = new DbService(Credentials);
Client = new DiscordSocketClient(new DiscordSocketConfig
{
@ -185,7 +185,6 @@ namespace NadekoBot
throw;
}
toReturn.Add(x);
//_log.Info("Loaded {0} typereader.", x.GetType().Name);
}
return toReturn;