Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add reverse indexes on Localizations and SearchTags #1971

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;

namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence.Configurations.Dialogs;

Expand All @@ -11,7 +11,7 @@ public void Configure(EntityTypeBuilder<DialogEntity> builder)
{
builder.ToTable("Dialog");
builder.Property(x => x.ServiceResource)
.HasMaxLength(Constants.DefaultMaxStringLength);
.HasMaxLength(DefaultMaxStringLength);
builder.HasIndex(x => x.CreatedAt);
builder.HasIndex(x => x.DueAt);
builder.HasIndex(x => x.UpdatedAt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using Digdir.Domain.Dialogporten.Domain.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;

namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence.Configurations.Dialogs;

internal sealed class DialogSearchTagConfiguration : IEntityTypeConfiguration<DialogSearchTag>
{
public void Configure(EntityTypeBuilder<DialogSearchTag> builder)
{
builder.HasIndex(x => new { x.DialogId, x.Value })
.IsUnique();
builder.Property(x => x.Value)
.HasMaxLength(Constants.MaxSearchTagLength);
.HasMaxLength(MaxSearchTagLength);

builder.HasIndex(x => x.Value)
.HasMethod(Constants.Gin)
.HasOperators(Constants.GinTrgmOps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ public void Configure(EntityTypeBuilder<Localization> builder)
builder.HasKey(x => new { x.LocalizationSetId, CultureCode = x.LanguageCode });
builder.Property(x => x.LanguageCode).HasMaxLength(15);
builder.Property(x => x.Value).HasMaxLength(4095);

builder.HasIndex(x => x.Value)
.HasMethod(Constants.Gin)
.HasOperators(Constants.GinTrgmOps);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence;

internal static class Constants
{
internal const string Gin = "gin";
internal const string GinTrgmOps = "gin_trgm_ops";
internal const string PostgreSqlTrigram = "pg_trgm";
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public async Task<List<Guid>> GetExistingIds<TEntity>(

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Properties<string>(x => x.HaveMaxLength(Constants.DefaultMaxStringLength));
configurationBuilder.Properties<Uri>(x => x.HaveMaxLength(Constants.DefaultMaxUriLength));
configurationBuilder.Properties<string>(x => x.HaveMaxLength(Domain.Common.Constants.DefaultMaxStringLength));
configurationBuilder.Properties<Uri>(x => x.HaveMaxLength(Domain.Common.Constants.DefaultMaxUriLength));
configurationBuilder.Properties<DateTimeOffset>().HaveConversion<DateTimeOffsetConverter>();
configurationBuilder.Properties<TimeSpan>().HaveConversion<TimeSpanToStringConverter>();
}
Expand All @@ -113,6 +113,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)


modelBuilder
.HasPostgresExtension(Constants.PostgreSqlTrigram)
.RemovePluralizingTableNameConvention()
.AddAuditableEntities()
.ApplyConfigurationsFromAssembly(typeof(DialogDbContext).Assembly)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Digdir.Domain.Dialogporten.Domain.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;

namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence.IdempotentNotifications;

Expand All @@ -17,7 +18,7 @@ public void Configure(EntityTypeBuilder<NotificationAcknowledgement> builder)
{
builder.HasKey(x => new { x.EventId, x.NotificationHandler });
builder.HasIndex(x => x.EventId);
builder.Property(x => x.NotificationHandler).HasMaxLength(Constants.DefaultMaxStringLength);
builder.Property(x => x.NotificationHandler).HasMaxLength(DefaultMaxStringLength);
builder.Property(x => x.AcknowledgedAt).HasDefaultValueSql("current_timestamp at time zone 'utc'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using MassTransit;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using Constants = Digdir.Domain.Dialogporten.Infrastructure.GraphQl.GraphQlSubscriptionConstants;

namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence.Interceptors;

Expand Down Expand Up @@ -103,7 +102,7 @@ public override async ValueTask<int> SavedChangesAsync(SaveChangesCompletedEvent
.Where(x => x is not null)
.Cast<DialogEventPayload>()
.Select(x => _topicEventSender.Value.SendAsync(
$"{Constants.DialogEventsTopic}{x.Id}",
$"{GraphQlSubscriptionConstants.DialogEventsTopic}{x.Id}",
x,
cancellationToken)
.AsTask());
Expand Down
Loading