Skip to content

Commit

Permalink
Added database indexes for (much) better performance on public bot ho…
Browse files Browse the repository at this point in the history
…pefully.
  • Loading branch information
Wizkiller96 committed Feb 10, 2018
1 parent baa8ea4 commit c70f7ad
Show file tree
Hide file tree
Showing 20 changed files with 2,498 additions and 51 deletions.
2,197 changes: 2,197 additions & 0 deletions WizBot.Core/Migrations/20180209202506_indexes.Designer.cs

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions WizBot.Core/Migrations/20180209202506_indexes.cs
@@ -0,0 +1,159 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace WizBot.Migrations
{
public partial class indexes : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_Warnings_DateAdded",
table: "Warnings",
column: "DateAdded");

migrationBuilder.CreateIndex(
name: "IX_Warnings_GuildId",
table: "Warnings",
column: "GuildId");

migrationBuilder.CreateIndex(
name: "IX_Warnings_UserId",
table: "Warnings",
column: "UserId");

migrationBuilder.CreateIndex(
name: "IX_WaifuInfo_Price",
table: "WaifuInfo",
column: "Price");

migrationBuilder.CreateIndex(
name: "IX_UserXpStats_AwardedXp",
table: "UserXpStats",
column: "AwardedXp");

migrationBuilder.CreateIndex(
name: "IX_UserXpStats_GuildId",
table: "UserXpStats",
column: "GuildId");

migrationBuilder.CreateIndex(
name: "IX_UserXpStats_UserId",
table: "UserXpStats",
column: "UserId");

migrationBuilder.CreateIndex(
name: "IX_UserXpStats_Xp",
table: "UserXpStats",
column: "Xp");

migrationBuilder.CreateIndex(
name: "IX_Reminders_DateAdded",
table: "Reminders",
column: "DateAdded");

migrationBuilder.CreateIndex(
name: "IX_Quotes_GuildId",
table: "Quotes",
column: "GuildId");

migrationBuilder.CreateIndex(
name: "IX_Quotes_Keyword",
table: "Quotes",
column: "Keyword");

migrationBuilder.CreateIndex(
name: "IX_Donators_Amount",
table: "Donators",
column: "Amount");

migrationBuilder.CreateIndex(
name: "IX_DiscordUser_CurrencyAmount",
table: "DiscordUser",
column: "CurrencyAmount");

migrationBuilder.CreateIndex(
name: "IX_DiscordUser_TotalXp",
table: "DiscordUser",
column: "TotalXp");

migrationBuilder.CreateIndex(
name: "IX_DiscordUser_UserId",
table: "DiscordUser",
column: "UserId");

migrationBuilder.CreateIndex(
name: "IX_CurrencyTransactions_DateAdded",
table: "CurrencyTransactions",
column: "DateAdded");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_Warnings_DateAdded",
table: "Warnings");

migrationBuilder.DropIndex(
name: "IX_Warnings_GuildId",
table: "Warnings");

migrationBuilder.DropIndex(
name: "IX_Warnings_UserId",
table: "Warnings");

migrationBuilder.DropIndex(
name: "IX_WaifuInfo_Price",
table: "WaifuInfo");

migrationBuilder.DropIndex(
name: "IX_UserXpStats_AwardedXp",
table: "UserXpStats");

migrationBuilder.DropIndex(
name: "IX_UserXpStats_GuildId",
table: "UserXpStats");

migrationBuilder.DropIndex(
name: "IX_UserXpStats_UserId",
table: "UserXpStats");

migrationBuilder.DropIndex(
name: "IX_UserXpStats_Xp",
table: "UserXpStats");

migrationBuilder.DropIndex(
name: "IX_Reminders_DateAdded",
table: "Reminders");

migrationBuilder.DropIndex(
name: "IX_Quotes_GuildId",
table: "Quotes");

migrationBuilder.DropIndex(
name: "IX_Quotes_Keyword",
table: "Quotes");

migrationBuilder.DropIndex(
name: "IX_Donators_Amount",
table: "Donators");

migrationBuilder.DropIndex(
name: "IX_DiscordUser_CurrencyAmount",
table: "DiscordUser");

migrationBuilder.DropIndex(
name: "IX_DiscordUser_TotalXp",
table: "DiscordUser");

migrationBuilder.DropIndex(
name: "IX_DiscordUser_UserId",
table: "DiscordUser");

migrationBuilder.DropIndex(
name: "IX_CurrencyTransactions_DateAdded",
table: "CurrencyTransactions");
}
}
}
32 changes: 32 additions & 0 deletions WizBot.Core/Migrations/WizBotSqliteContextModelSnapshot.cs
Expand Up @@ -364,6 +364,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("DateAdded");
b.ToTable("CurrencyTransactions");
});

Expand Down Expand Up @@ -454,6 +456,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("ClubId");
b.HasIndex("CurrencyAmount");
b.HasIndex("TotalXp");
b.HasIndex("UserId");
b.ToTable("DiscordUser");
});

Expand All @@ -472,6 +480,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("Amount");
b.HasIndex("UserId")
.IsUnique();
Expand Down Expand Up @@ -1119,6 +1129,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("GuildId");
b.HasIndex("Keyword");
b.ToTable("Quotes");
});

Expand Down Expand Up @@ -1207,6 +1221,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("DateAdded");
b.ToTable("Reminders");
});

Expand Down Expand Up @@ -1519,6 +1535,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("AwardedXp");
b.HasIndex("GuildId");
b.HasIndex("UserId");
b.HasIndex("Xp");
b.HasIndex("UserId", "GuildId")
.IsUnique();
Expand Down Expand Up @@ -1566,6 +1590,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasIndex("ClaimerId");
b.HasIndex("Price");
b.HasIndex("WaifuId")
.IsUnique();
Expand Down Expand Up @@ -1641,6 +1667,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasKey("Id");
b.HasIndex("DateAdded");
b.HasIndex("GuildId");
b.HasIndex("UserId");
b.ToTable("Warnings");
});

Expand Down
3 changes: 0 additions & 3 deletions WizBot.Core/Modules/Music/Common/MusicPlayer.cs
Expand Up @@ -646,16 +646,13 @@ public async Task SetVoiceChannel(IVoiceChannel vch)

public async Task UpdateSongDurationsAsync()
{
var sw = Stopwatch.StartNew();
var (_, songs) = Queue.ToArray();
var toUpdate = songs
.Where(x => x.ProviderType == MusicType.YouTube
&& x.TotalTime == TimeSpan.Zero);

var vIds = toUpdate.Select(x => x.VideoId);

sw.Stop();
_log.Info(sw.Elapsed.TotalSeconds);
if (!vIds.Any())
return;

Expand Down
Expand Up @@ -32,7 +32,6 @@ public PermissionService(DiscordSocketClient client, DbService db, CommandHandle
_cmd = cmd;
_strings = strings;

var sw = Stopwatch.StartNew();
if (client.ShardId == 0)
TryMigratePermissions();

Expand Down
1 change: 0 additions & 1 deletion WizBot.Core/Modules/Utility/PatreonCommands.cs
Expand Up @@ -75,6 +75,5 @@ await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.ConfigureAwait(false);
}
}

}
}

0 comments on commit c70f7ad

Please sign in to comment.