diff --git a/Iceshrimp.Backend/Core/Database/Migrations/DatabaseContextModelSnapshot.cs b/Iceshrimp.Backend/Core/Database/Migrations/DatabaseContextModelSnapshot.cs index cb90ed07..eb3cb219 100644 --- a/Iceshrimp.Backend/Core/Database/Migrations/DatabaseContextModelSnapshot.cs +++ b/Iceshrimp.Backend/Core/Database/Migrations/DatabaseContextModelSnapshot.cs @@ -981,6 +981,16 @@ namespace Iceshrimp.Backend.Core.Database.Migrations NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex("Name", "Host"), false); + b.HasIndex(new[] { "Host" }, "GIN_TRGM_emoji_host"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex(new[] { "Host" }, "GIN_TRGM_emoji_host"), "gin"); + NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex(new[] { "Host" }, "GIN_TRGM_emoji_host"), new[] { "gin_trgm_ops" }); + + b.HasIndex(new[] { "Name" }, "GIN_TRGM_emoji_name"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex(new[] { "Name" }, "GIN_TRGM_emoji_name"), "gin"); + NpgsqlIndexBuilderExtensions.HasOperators(b.HasIndex(new[] { "Name" }, "GIN_TRGM_emoji_name"), new[] { "gin_trgm_ops" }); + b.ToTable("emoji"); }); diff --git a/Iceshrimp.Backend/Core/Database/Migrations/v2025.1-beta6/20250307145204_EmojiNameHostIndex.cs b/Iceshrimp.Backend/Core/Database/Migrations/v2025.1-beta6/20250307145204_EmojiNameHostIndex.cs new file mode 100644 index 00000000..0d390858 --- /dev/null +++ b/Iceshrimp.Backend/Core/Database/Migrations/v2025.1-beta6/20250307145204_EmojiNameHostIndex.cs @@ -0,0 +1,43 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Infrastructure; + +#nullable disable + +namespace Iceshrimp.Backend.Core.Database.Migrations +{ + /// + [DbContext(typeof(DatabaseContext))] + [Migration("20250307145204_EmojiNameHostIndex")] + public partial class EmojiNameHostIndex : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "GIN_TRGM_emoji_host", + table: "emoji", + column: "host") + .Annotation("Npgsql:IndexMethod", "gin") + .Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" }); + + migrationBuilder.CreateIndex( + name: "GIN_TRGM_emoji_name", + table: "emoji", + column: "name") + .Annotation("Npgsql:IndexMethod", "gin") + .Annotation("Npgsql:IndexOperators", new[] { "gin_trgm_ops" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "GIN_TRGM_emoji_host", + table: "emoji"); + + migrationBuilder.DropIndex( + name: "GIN_TRGM_emoji_name", + table: "emoji"); + } + } +} diff --git a/Iceshrimp.Backend/Core/Database/Tables/Emoji.cs b/Iceshrimp.Backend/Core/Database/Tables/Emoji.cs index 69a2b975..73d0164b 100644 --- a/Iceshrimp.Backend/Core/Database/Tables/Emoji.cs +++ b/Iceshrimp.Backend/Core/Database/Tables/Emoji.cs @@ -80,6 +80,13 @@ public class Emoji entity.Property(e => e.RawPublicUrl).HasDefaultValueSql("''::character varying"); entity.Property(e => e.Width).HasComment("Image width"); + entity.HasIndex(e => e.Name, "GIN_TRGM_emoji_name") + .HasMethod("gin") + .HasOperators("gin_trgm_ops"); + entity.HasIndex(e => e.Host, "GIN_TRGM_emoji_host") + .HasMethod("gin") + .HasOperators("gin_trgm_ops"); + // This index must be NULLS NOT DISTINCT to make having multiple local emoji with the same name cause a constraint failure entity.HasIndex(nameof(Name), nameof(Host)).IsUnique().AreNullsDistinct(false); }