Skip to content

Commit

Permalink
feat: Add reverse indexes on Localizations and SearchTags (#1971)
Browse files Browse the repository at this point in the history
<!--- 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 <[email protected]>
Co-authored-by: Magnus Sandgren
<[email protected]>
  • Loading branch information
oskogstad authored Feb 28, 2025
1 parent 1cbc1c7 commit 7a506b3
Show file tree
Hide file tree
Showing 10 changed files with 2,346 additions and 15 deletions.
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

0 comments on commit 7a506b3

Please sign in to comment.