[backend/database] Add gin_trgm index for Emoji Name and Host
This commit is contained in:
parent
026cfa0e82
commit
dcc6fd3a19
3 changed files with 60 additions and 0 deletions
|
@ -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");
|
||||
});
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue