Skip to content

Commit

Permalink
major performance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SylveonDeko committed Sep 2, 2022
1 parent 2db9a04 commit dea7705
Show file tree
Hide file tree
Showing 53 changed files with 21 additions and 68 deletions.
1 change: 0 additions & 1 deletion src/Mewdeko/Common/Collections/ConcurrentHashSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Concurrent;
using System.Diagnostics;

namespace Mewdeko.Common.Collections;
Expand Down
3 changes: 1 addition & 2 deletions src/Mewdeko/Common/DownloadTracker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;

namespace Mewdeko.Common;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Common/Replacements/ReplacementBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Discord.Commands;
using Mewdeko.Modules.Administration.Services;
using NekosBestApiNet;
using System.Collections.Concurrent;
using System.Text.RegularExpressions;

namespace Mewdeko.Common.Replacements;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mewdeko.Database.Common;
using System.Collections.Concurrent;
using System.Security.Cryptography;
using System.Threading.Tasks;

Expand Down
1 change: 1 addition & 0 deletions src/Mewdeko/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
global using System;
global using System.Collections;
global using System.Collections.Generic;
global using NonBlocking;
global using System.Linq;
global using EventHandler = Mewdeko.Services.Impl.EventHandler;
1 change: 1 addition & 0 deletions src/Mewdeko/Mewdeko.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<PackageReference Include="NekosBestApiNet" Version="1.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1" />
<PackageReference Include="NHentaiAPI" Version="1.5.0" />
<PackageReference Include="NonBlocking" Version="2.1.0" />
<PackageReference Include="PokeApiNet" Version="3.0.8" />
<PackageReference Include="Scrutor" Version="4.2.0" />
<PackageReference Include="Serilog" Version="2.11.1-dev-01397" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mewdeko.Common.Collections;
using System.Collections.Concurrent;
using System.Threading;

namespace Mewdeko.Modules.Administration.Common;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Discord.Commands;
using Mewdeko.Common.Collections;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Administration.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Discord.Interactions;
using Mewdeko.Common.ModuleBehaviors;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using PreconditionResult = Discord.Commands.PreconditionResult;
using RequireUserPermissionAttribute = Discord.Commands.RequireUserPermissionAttribute;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Administration.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Mewdeko.Services.strings;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Mewdeko.Modules.Moderation.Services;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Administration.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mewdeko.Database.Common;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Administration.Services;
Expand Down
12 changes: 6 additions & 6 deletions src/Mewdeko/Modules/Administration/Services/VcRoleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public VcRoleService(DiscordSocketClient client, Mewdeko bot, DbService db, Even
_client = client;

eventHandler.UserVoiceStateUpdated += ClientOnUserVoiceStateUpdated;
VcRoles = new ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>>();
ToAssign = new ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>>();
VcRoles = new NonBlocking.ConcurrentDictionary<ulong, NonBlocking.ConcurrentDictionary<ulong, IRole>>();
ToAssign = new NonBlocking.ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>>();

using (var uow = db.GetDbContext())
{
Expand Down Expand Up @@ -81,8 +81,8 @@ public VcRoleService(DiscordSocketClient client, Mewdeko bot, DbService db, Even
bot.JoinedGuild += Bot_JoinedGuild;
}

public ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>> VcRoles { get; }
public ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>> ToAssign { get; }
public NonBlocking.ConcurrentDictionary<ulong, NonBlocking.ConcurrentDictionary<ulong, IRole>> VcRoles { get; }
public NonBlocking.ConcurrentDictionary<ulong, System.Collections.Concurrent.ConcurrentQueue<(bool, IGuildUser, IRole)>> ToAssign { get; }

private async Task Bot_JoinedGuild(GuildConfig arg)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ private async Task InitializeVcRole(GuildConfig gconf)
if (g == null)
return;

var infos = new ConcurrentDictionary<ulong, IRole>();
var infos = new NonBlocking.ConcurrentDictionary<ulong, IRole>();
var missingRoles = new List<VcRoleInfo>();
VcRoles.AddOrUpdate(gconf.GuildId, infos, delegate { return infos; });
foreach (var ri in gconf.VcRoleInfos)
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task AddVcRole(ulong guildId, IRole role, ulong vcId)
if (role == null)
throw new ArgumentNullException(nameof(role));

var guildVcRoles = VcRoles.GetOrAdd(guildId, new ConcurrentDictionary<ulong, IRole>());
var guildVcRoles = VcRoles.GetOrAdd(guildId, new NonBlocking.ConcurrentDictionary<ulong, IRole>());

guildVcRoles.AddOrUpdate(vcId, role, (_, _) => role);
await using var uow = _db.GetDbContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Mewdeko.Services.strings;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down
2 changes: 0 additions & 2 deletions src/Mewdeko/Modules/Gambling/Common/Events/ReactionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class ReactionEvent : ICurrencyEvent
private readonly long _amount;
private readonly ConcurrentHashSet<ulong> _awardedUsers = new();
private readonly ITextChannel _channel;
private readonly DiscordSocketClient _client;
private readonly GamblingConfig _config;
private readonly ICurrencyService _cs;

Expand All @@ -36,7 +35,6 @@ public ReactionEvent(DiscordSocketClient client, ICurrencyService cs,
Func<CurrencyEvent.Type, EventOptions, long, EmbedBuilder> embedFunc,
EventHandler eventHandler)
{
_client = client;
_guild = g;
_cs = cs;
_amount = opt.Amount;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Gambling/DrawCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Mewdeko.Modules.Gambling.Common;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;
using Image = SixLabors.ImageSharp.Image;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Gambling/Services/AnimalRaceService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mewdeko.Modules.Gambling.Common.AnimalRacing;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Gambling.Services;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Gambling/Services/BlackJackService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mewdeko.Modules.Gambling.Common.Blackjack;
using System.Collections.Concurrent;

namespace Mewdeko.Modules.Gambling.Services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Mewdeko.Modules.Gambling.Common.Events;
using Serilog;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Gambling.Services;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Gambling/Services/GamblingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Serilog;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Gambling/Services/PlantPickService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Games/Common/Trivia/TriviaGame.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Discord.Net;
using Mewdeko.Services.strings;
using Serilog;
using System.Collections.Concurrent;
using System.Net;
using System.Text;
using System.Threading;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Games/Services/ChatterbotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Mewdeko.Modules.Games.Common.ChatterBot;
using Mewdeko.Modules.Permissions.Services;
using Serilog;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading.Tasks;

Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Games/Services/GamesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Mewdeko.Modules.Games.Common.Trivia;
using Newtonsoft.Json;
using Serilog;
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;

Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Games/Services/PollService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mewdeko.Database.Common;
using Mewdeko.Modules.Games.Common;
using Serilog;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Games.Services;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Moderation/Services/MuteService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mewdeko.Common.Collections;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Music/Services/MusicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Lavalink4NET.Rest;
using Mewdeko.Modules.Music.Common;
using SpotifyAPI.Web;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading.Tasks;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Net.Http;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;
Expand Down
3 changes: 1 addition & 2 deletions src/Mewdeko/Modules/Nsfw/ISearchImagesService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Nsfw;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Nsfw/Nsfw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Mewdeko.Common.Collections;
using Newtonsoft.Json.Linq;
using NHentaiAPI;
using NHentaiAPI.Models.Books;
using Refit;
using Serilog;
using System.Net.Http;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Nsfw/SearchImageCacher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Mewdeko.Modules.Nsfw.Common.Downloaders;
using Microsoft.Extensions.Caching.Memory;
using Serilog;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Nsfw/SearchImagesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Serilog;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/OwnerOnly/Services/OwnerOnlyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Newtonsoft.Json;
using Serilog;
using StackExchange.Redis;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Net.Http;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Permissions/CmdCdsCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Mewdeko.Common.TypeReaders;
using Mewdeko.Modules.Permissions.Services;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Permissions;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Permissions/Services/CmdCdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Discord.Interactions;
using Mewdeko.Common.Collections;
using Mewdeko.Common.ModuleBehaviors;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Permissions.Services;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Permissions/Services/FilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Mewdeko.Services.strings;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Globalization;
using System.Threading.Tasks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Mewdeko.Modules.Permissions.Common;
using Mewdeko.Services.strings;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Permissions.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mewdeko.Modules.Searches.Common.StreamNotifications.Models;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Searches.Common.StreamNotifications.Providers;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Searches/Searches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Collections.Concurrent;
using System.Globalization;
using System.Net;
using System.Net.Http;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Searches/Services/FeedsService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CodeHollow.FeedReader;
using CodeHollow.FeedReader.Feeds;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Embed = Discord.Embed;

Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Searches/Services/SearchesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Net;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Server_Management.Services;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Utility/CommandMapCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Mewdeko.Common.Attributes.TextCommands;
using Mewdeko.Modules.Utility.Services;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Utility;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Utility/RepeatCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Mewdeko.Modules.Utility.Common;
using Mewdeko.Modules.Utility.Services;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Utility;
Expand Down
1 change: 0 additions & 1 deletion src/Mewdeko/Modules/Utility/Services/CommandMapService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Mewdeko.Common.ModuleBehaviors;
using Microsoft.EntityFrameworkCore;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Utility.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mewdeko.Modules.Utility.Common;
using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Mewdeko.Modules.Utility.Services;
Expand Down
Loading

0 comments on commit dea7705

Please sign in to comment.