Much better startup time on shared bot
This commit is contained in:
		| @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration | ||||
|         { | ||||
|             using (var uow = DbHandler.UnitOfWork()) | ||||
|             { | ||||
|                 var configs = uow.GuildConfigs.GetAll(); | ||||
|                 var configs = NadekoBot.AllGuildConfigs; | ||||
|                 GuildMuteRoles = new ConcurrentDictionary<ulong, string>(configs | ||||
|                         .Where(c=>!string.IsNullOrWhiteSpace(c.MuteRoleName)) | ||||
|                         .ToDictionary(c => c.GuildId, c => c.MuteRoleName)); | ||||
|   | ||||
| @@ -41,8 +41,7 @@ namespace NadekoBot.Modules.Administration | ||||
|  | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 { | ||||
|                     GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(uow.GuildConfigs | ||||
|                                                                                       .GetAll() | ||||
|                     GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(NadekoBot.AllGuildConfigs | ||||
|                                                                                       .ToDictionary(g => g.GuildId, g => g.LogSetting)); | ||||
|                 } | ||||
|  | ||||
|   | ||||
| @@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Administration | ||||
|             { | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 { | ||||
|                     voicePlusTextCache = new ConcurrentHashSet<ulong>(uow.GuildConfigs.GetAll().Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); | ||||
|                     voicePlusTextCache = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); | ||||
|                 } | ||||
|                 NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; | ||||
|             } | ||||
|   | ||||
| @@ -54,7 +54,7 @@ namespace NadekoBot.Modules.Games | ||||
|                 { | ||||
|                     var conf = uow.BotConfig.GetOrCreate(); | ||||
|                     var x = | ||||
|                     generationChannels = new ConcurrentHashSet<ulong>(uow.GuildConfigs.GetAll() | ||||
|                     generationChannels = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs | ||||
|                         .SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj=>obj.ChannelId))); | ||||
|                     chance = conf.CurrencyGenerationChance; | ||||
|                     cooldown = conf.CurrencyGenerationCooldown; | ||||
|   | ||||
| @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Permissions | ||||
|             { | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 { | ||||
|                     var configs = uow.GuildConfigs.GetAll(); | ||||
|                     var configs = NadekoBot.AllGuildConfigs; | ||||
|                     commandCooldowns = new ConcurrentDictionary<ulong, ConcurrentHashSet<CommandCooldown>>(configs.ToDictionary(k => k.GuildId, v => new ConcurrentHashSet<CommandCooldown>(v.CommandCooldowns))); | ||||
|                 } | ||||
|             } | ||||
|   | ||||
| @@ -46,7 +46,7 @@ namespace NadekoBot.Modules.Permissions | ||||
|             { | ||||
|                 using (var uow = DbHandler.UnitOfWork()) | ||||
|                 { | ||||
|                     var guildConfigs = uow.GuildConfigs.GetAll(); | ||||
|                     var guildConfigs = NadekoBot.AllGuildConfigs; | ||||
|  | ||||
|                     InviteFilteringServers = new ConcurrentHashSet<ulong>(guildConfigs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId)); | ||||
|                     InviteFilteringChannels = new ConcurrentHashSet<ulong>(guildConfigs.SelectMany(gc => gc.FilterInvitesChannelIds.Select(fci => fci.ChannelId))); | ||||
|   | ||||
| @@ -19,6 +19,7 @@ using Module = Discord.Commands.Module; | ||||
| using NadekoBot.TypeReaders; | ||||
| using System.Collections.Concurrent; | ||||
| using NadekoBot.Modules.Music; | ||||
| using NadekoBot.Services.Database.Models; | ||||
|  | ||||
| namespace NadekoBot | ||||
| { | ||||
| @@ -38,6 +39,16 @@ namespace NadekoBot | ||||
|         public static ConcurrentDictionary<string, string> ModulePrefixes { get; private set; } | ||||
|         public static bool Ready { get; private set; } | ||||
|  | ||||
|         public static IEnumerable<GuildConfig> AllGuildConfigs { get; } | ||||
|  | ||||
|         static NadekoBot() | ||||
|         { | ||||
|             using (var uow = DbHandler.UnitOfWork()) | ||||
|             { | ||||
|                 AllGuildConfigs = uow.GuildConfigs.GetAll(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task RunAsync(string[] args) | ||||
|         { | ||||
|             SetupLogger(); | ||||
|   | ||||
| @@ -19,18 +19,19 @@ namespace NadekoBot.Services | ||||
|         static DbHandler() { } | ||||
|  | ||||
|         private DbHandler() { | ||||
|             switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant()) | ||||
|             { | ||||
|                 case "SQLITE": | ||||
|                     dbType = typeof(NadekoSqliteContext); | ||||
|                     break; | ||||
|                 //case "SQLSERVER": | ||||
|                 //    dbType = typeof(NadekoSqlServerContext); | ||||
|                 //    break; | ||||
|                 default: | ||||
|                     break; | ||||
|             dbType = typeof(NadekoSqliteContext); | ||||
|             //switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant()) | ||||
|             //{ | ||||
|             //    case "SQLITE": | ||||
|             //        dbType = typeof(NadekoSqliteContext); | ||||
|             //        break; | ||||
|             //    //case "SQLSERVER": | ||||
|             //    //    dbType = typeof(NadekoSqlServerContext); | ||||
|             //    //    break; | ||||
|             //    default: | ||||
|             //        break; | ||||
|  | ||||
|             } | ||||
|             //} | ||||
|         } | ||||
|  | ||||
|         public NadekoContext GetDbContext() =>  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user