Skip to content

Commit 7a506b3

Browse files
authored
feat: Add reverse indexes on Localizations and SearchTags (#1971)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue(s) - #[1650](#1650) ## Verification - [x] **Your** code builds clean without any errors or warnings - [x] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) Co-authored-by: Bjørn Dybvik Langfors <bdl@digdir.no> Co-authored-by: Magnus Sandgren <5285192+MagnusSandgren@users.noreply.github.com>
1 parent 1cbc1c7 commit 7a506b3

10 files changed

+2346
-15
lines changed

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogEntityConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Digdir.Domain.Dialogporten.Domain.Common;
2-
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
1+
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
32
using Microsoft.EntityFrameworkCore;
43
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;
55

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

@@ -11,7 +11,7 @@ public void Configure(EntityTypeBuilder<DialogEntity> builder)
1111
{
1212
builder.ToTable("Dialog");
1313
builder.Property(x => x.ServiceResource)
14-
.HasMaxLength(Constants.DefaultMaxStringLength);
14+
.HasMaxLength(DefaultMaxStringLength);
1515
builder.HasIndex(x => x.CreatedAt);
1616
builder.HasIndex(x => x.DueAt);
1717
builder.HasIndex(x => x.UpdatedAt);
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
using Digdir.Domain.Dialogporten.Domain.Common;
21
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities;
32
using Microsoft.EntityFrameworkCore;
43
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;
55

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

88
internal sealed class DialogSearchTagConfiguration : IEntityTypeConfiguration<DialogSearchTag>
99
{
1010
public void Configure(EntityTypeBuilder<DialogSearchTag> builder)
1111
{
12-
builder.HasIndex(x => new { x.DialogId, x.Value })
13-
.IsUnique();
1412
builder.Property(x => x.Value)
15-
.HasMaxLength(Constants.MaxSearchTagLength);
13+
.HasMaxLength(MaxSearchTagLength);
14+
15+
builder.HasIndex(x => x.Value)
16+
.HasMethod(Constants.Gin)
17+
.HasOperators(Constants.GinTrgmOps);
1618
}
1719
}

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Localizations/LocalizationConfiguration.cs

+5
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ public void Configure(EntityTypeBuilder<Localization> builder)
1111
builder.HasKey(x => new { x.LocalizationSetId, CultureCode = x.LanguageCode });
1212
builder.Property(x => x.LanguageCode).HasMaxLength(15);
1313
builder.Property(x => x.Value).HasMaxLength(4095);
14+
15+
builder.HasIndex(x => x.Value)
16+
.HasMethod(Constants.Gin)
17+
.HasOperators(Constants.GinTrgmOps);
18+
1419
}
1520
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Digdir.Domain.Dialogporten.Infrastructure.Persistence;
2+
3+
internal static class Constants
4+
{
5+
internal const string Gin = "gin";
6+
internal const string GinTrgmOps = "gin_trgm_ops";
7+
internal const string PostgreSqlTrigram = "pg_trgm";
8+
}

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public async Task<List<Guid>> GetExistingIds<TEntity>(
100100

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

114114

115115
modelBuilder
116+
.HasPostgresExtension(Constants.PostgreSqlTrigram)
116117
.RemovePluralizingTableNameConvention()
117118
.AddAuditableEntities()
118119
.ApplyConfigurationsFromAssembly(typeof(DialogDbContext).Assembly)

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/IdempotentNotifications/NotificationAcknowledgement.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Digdir.Domain.Dialogporten.Domain.Common;
22
using Microsoft.EntityFrameworkCore;
33
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
using static Digdir.Domain.Dialogporten.Domain.Common.Constants;
45

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

@@ -17,7 +18,7 @@ public void Configure(EntityTypeBuilder<NotificationAcknowledgement> builder)
1718
{
1819
builder.HasKey(x => new { x.EventId, x.NotificationHandler });
1920
builder.HasIndex(x => x.EventId);
20-
builder.Property(x => x.NotificationHandler).HasMaxLength(Constants.DefaultMaxStringLength);
21+
builder.Property(x => x.NotificationHandler).HasMaxLength(DefaultMaxStringLength);
2122
builder.Property(x => x.AcknowledgedAt).HasDefaultValueSql("current_timestamp at time zone 'utc'");
2223
}
2324
}

src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Interceptors/ConvertDomainEventsToOutboxMessagesInterceptor.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using MassTransit;
88
using Microsoft.EntityFrameworkCore.Diagnostics;
99
using Microsoft.Extensions.Logging;
10-
using Constants = Digdir.Domain.Dialogporten.Infrastructure.GraphQl.GraphQlSubscriptionConstants;
1110

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

@@ -103,7 +102,7 @@ public override async ValueTask<int> SavedChangesAsync(SaveChangesCompletedEvent
103102
.Where(x => x is not null)
104103
.Cast<DialogEventPayload>()
105104
.Select(x => _topicEventSender.Value.SendAsync(
106-
$"{Constants.DialogEventsTopic}{x.Id}",
105+
$"{GraphQlSubscriptionConstants.DialogEventsTopic}{x.Id}",
107106
x,
108107
cancellationToken)
109108
.AsTask());

0 commit comments

Comments
 (0)