[backend/database] Add gin_trgm index for Emoji Name and Host

This commit is contained in:
pancakes 2025-03-08 01:06:19 +10:00 committed by Laura Hausmann
parent 026cfa0e82
commit dcc6fd3a19
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 60 additions and 0 deletions

View file

@ -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");
});

View file

@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
[DbContext(typeof(DatabaseContext))]
[Migration("20250307145204_EmojiNameHostIndex")]
public partial class EmojiNameHostIndex : Migration
{
/// <inheritdoc />
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" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "GIN_TRGM_emoji_host",
table: "emoji");
migrationBuilder.DropIndex(
name: "GIN_TRGM_emoji_name",
table: "emoji");
}
}
}

View file

@ -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);
}