refactor(dir): ♻ map lang surrogate key, convert all surrogate keys to longs

This commit is contained in:
Collin M. Barrett 2021-11-26 11:25:06 -06:00
parent 774b6d272c
commit 2965533102
34 changed files with 78 additions and 83 deletions

View file

@ -10,7 +10,7 @@ namespace FilterLists.Archival.Application.Commands;
public static class ArchiveList
{
public record Command(int ListId) : IRequest;
public record Command(long ListId) : IRequest;
internal class Handler : IRequestHandler<Command, Unit>
{
@ -56,7 +56,7 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
}
private async Task<IEnumerable<ListDetailsVm.ViewUrlVm>> GetSegmentUrlsAsync(
int listId,
long listId,
CancellationToken cancellationToken)
{
var listDetails = await _directory.GetListDetailsAsync(listId, cancellationToken);
@ -66,7 +66,7 @@ public async Task<Unit> Handle(Command request, CancellationToken cancellationTo
}
private ListArchive GetList(
int listId,
long listId,
IEnumerable<ListDetailsVm.ViewUrlVm> segmentUrls,
CancellationToken cancellationToken)
{

View file

@ -1,3 +1,3 @@
namespace FilterLists.Archival.Domain.ListArchives;
public record ListArchive(int Id, IAsyncEnumerable<ListArchiveSegment> Segments);
public record ListArchive(long Id, IAsyncEnumerable<ListArchiveSegment> Segments);

View file

@ -102,7 +102,7 @@ public void Dispose()
_repo.CheckoutPaths("HEAD", _writtenFiles.Select(f => f.Name));
}
private FileInfo? GetTargetFile(int listId, int segmentNumber, ListFileExtension extension)
private FileInfo? GetTargetFile(long listId, int segmentNumber, ListFileExtension extension)
{
string targetExtension;
if (extension.IsPlainText)
@ -121,7 +121,7 @@ public void Dispose()
return new FileInfo(Path.Combine(_options.RepositoryPath, targetFileName));
}
private static string GetTargetFileNamePrefix(int listId)
private static string GetTargetFileNamePrefix(long listId)
{
return listId.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0');
}

View file

@ -9,5 +9,5 @@ public interface IDirectoryApi
Task<IEnumerable<ListVm>> GetListsAsync(CancellationToken cancellationToken);
[Get("/lists/{id}")]
Task<ListDetailsVm> GetListDetailsAsync(int id, CancellationToken cancellationToken);
Task<ListDetailsVm> GetListDetailsAsync(long id, CancellationToken cancellationToken);
}

View file

@ -2,13 +2,13 @@
public record ListDetailsVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public int? LicenseId { get; init; }
public IEnumerable<int> SyntaxIds { get; init; } = new HashSet<int>();
public IEnumerable<string> Iso6391s { get; init; } = new HashSet<string>();
public IEnumerable<int> TagIds { get; init; } = new HashSet<int>();
public long? LicenseId { get; init; }
public IEnumerable<long> SyntaxIds { get; init; } = new HashSet<long>();
public IEnumerable<long> LanguageIds { get; init; } = new HashSet<long>();
public IEnumerable<long> TagIds { get; init; } = new HashSet<long>();
public IEnumerable<ViewUrlVm> ViewUrls { get; init; } = new HashSet<ViewUrlVm>();
public Uri? HomeUrl { get; init; }
public Uri? OnionUrl { get; init; }
@ -19,13 +19,13 @@ public record ListDetailsVm
public Uri? ChatUrl { get; init; }
public string? EmailAddress { get; init; }
public Uri? DonateUrl { get; init; }
public IEnumerable<int> MaintainerIds { get; init; } = new HashSet<int>();
public IEnumerable<int> UpstreamFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> ForkFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> IncludedInFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> IncludesFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> DependencyFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> DependentFilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<long> MaintainerIds { get; init; } = new HashSet<long>();
public IEnumerable<long> UpstreamFilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> ForkFilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> IncludedInFilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> IncludesFilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> DependencyFilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> DependentFilterListIds { get; init; } = new HashSet<long>();
public record ViewUrlVm
{

View file

@ -2,13 +2,13 @@
public record ListVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public int? LicenseId { get; init; }
public IEnumerable<int> SyntaxIds { get; init; } = new HashSet<int>();
public IEnumerable<string> Iso6391s { get; init; } = new HashSet<string>();
public IEnumerable<int> TagIds { get; init; } = new HashSet<int>();
public long? LicenseId { get; init; }
public IEnumerable<long> SyntaxIds { get; init; } = new HashSet<long>();
public IEnumerable<long> LanguageIds { get; init; } = new HashSet<long>();
public IEnumerable<long> TagIds { get; init; } = new HashSet<long>();
public Uri? PrimaryViewUrl { get; init; }
public IEnumerable<int> MaintainerIds { get; init; } = new HashSet<int>();
public IEnumerable<long> MaintainerIds { get; init; } = new HashSet<long>();
}

View file

@ -19,7 +19,7 @@ protected BaseController(IMemoryCache cache)
/// <remarks>https://stackoverflow.com/a/52506210/2343739</remarks>
protected async Task<IActionResult> CacheGetOrCreateAsync<TResponse>(
Func<Task<TResponse>> actionAsync,
int? keySuffix = default,
long? keySuffix = default,
TimeSpan? absoluteExpirationRelativeToNow = default,
[CallerMemberName] string key = default!)
{

View file

@ -33,10 +33,10 @@ public Task<IActionResult> Get(CancellationToken cancellationToken)
/// <param name="id">The identifier of the FilterList.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The details of the FilterList.</returns>
[HttpGet("{id:int}")]
[HttpGet("{id:long}")]
[ProducesResponseType(typeof(ListDetailsVm), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public Task<IActionResult> GetDetails(int id, CancellationToken cancellationToken)
public Task<IActionResult> GetDetails(long id, CancellationToken cancellationToken)
{
return CacheGetOrCreateAsync(() => _mediator.Send(new GetListDetails.Query(id), cancellationToken), id);
}

View file

@ -46,8 +46,9 @@ public LanguageVmProfile()
public record LanguageVm
{
public long Id { get; init; }
public string Iso6391 { get; init; } = null!;
public string Name { get; init; } = null!;
public IEnumerable<int> FilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<long> FilterListIds { get; init; } = new HashSet<long>();
}
}

View file

@ -44,12 +44,12 @@ public LicenseVmProfile()
public record LicenseVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public bool PermitsModification { get; init; }
public bool PermitsDistribution { get; init; }
public bool PermitsCommercialUse { get; init; }
public IEnumerable<int> FilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<long> FilterListIds { get; init; } = new HashSet<long>();
}
}

View file

@ -11,7 +11,7 @@ namespace FilterLists.Directory.Application.Queries;
public static class GetListDetails
{
public record Query(int Id) : IRequest<ListDetailsVm?>;
public record Query(long Id) : IRequest<ListDetailsVm?>;
internal class Validator : AbstractValidator<Query>
{
@ -51,9 +51,9 @@ public ListDetailsVmProfile()
.ForMember(fl => fl.SyntaxIds,
o => o.MapFrom(fl =>
fl.FilterListSyntaxes.OrderBy(fls => fls.SyntaxId).Select(fls => fls.SyntaxId)))
.ForMember(fl => fl.Iso6391s,
.ForMember(fl => fl.LanguageIds,
o => o.MapFrom(fl =>
fl.FilterListLanguages.OrderBy(fll => fll.Iso6391).Select(fll => fll.Iso6391)))
fl.FilterListLanguages.OrderBy(fll => fll.LanguageId).Select(fll => fll.LanguageId)))
.ForMember(fl => fl.TagIds,
o => o.MapFrom(fl =>
fl.FilterListTags.OrderBy(flt => flt.TagId).Select(flt => flt.TagId)))

View file

@ -42,9 +42,9 @@ public ListVmProfile()
.ForMember(fl => fl.SyntaxIds,
o => o.MapFrom(fl =>
fl.FilterListSyntaxes.OrderBy(fls => fls.SyntaxId).Select(fls => fls.SyntaxId)))
.ForMember(fl => fl.Iso6391s,
.ForMember(fl => fl.LanguageIds,
o => o.MapFrom(fl =>
fl.FilterListLanguages.OrderBy(fll => fll.Iso6391).Select(fll => fll.Iso6391)))
fl.FilterListLanguages.OrderBy(fll => fll.LanguageId).Select(fll => fll.LanguageId)))
.ForMember(fl => fl.TagIds,
o => o.MapFrom(fl =>
fl.FilterListTags.OrderBy(flt => flt.TagId).Select(flt => flt.TagId)))

View file

@ -46,11 +46,11 @@ public MaintainerVmProfile()
public record MaintainerVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public string? EmailAddress { get; init; }
public string? TwitterHandle { get; init; }
public IEnumerable<int> FilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<long> FilterListIds { get; init; } = new HashSet<long>();
}
}

View file

@ -45,12 +45,12 @@ public SoftwareVmProfile()
public record SoftwareVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? HomeUrl { get; init; }
public Uri? DownloadUrl { get; init; }
public bool SupportsAbpUrlScheme { get; init; }
public IEnumerable<int> SyntaxIds { get; init; } = new HashSet<int>();
public IEnumerable<long> SyntaxIds { get; init; } = new HashSet<long>();
}
}

View file

@ -49,11 +49,11 @@ public SyntaxVmProfile()
public record SyntaxVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? Url { get; init; }
public IEnumerable<int> FilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<int> SoftwareIds { get; init; } = new HashSet<int>();
public IEnumerable<long> FilterListIds { get; init; } = new HashSet<long>();
public IEnumerable<long> SoftwareIds { get; init; } = new HashSet<long>();
}
}

View file

@ -46,9 +46,9 @@ public TagVmProfile()
public record TagVm
{
public int Id { get; init; }
public long Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public IEnumerable<int> FilterListIds { get; init; } = new HashSet<int>();
public IEnumerable<long> FilterListIds { get; init; } = new HashSet<long>();
}
}

View file

@ -3,7 +3,7 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public abstract record AggregateRoot
public abstract record AggregateRoot : Entity
{
// TODO: change 'set' to 'init' when no longer seeding from json
public bool IsApproved { get; set; }

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Dependent
{
public int DependencyFilterListId { get; init; }
public long DependencyFilterListId { get; init; }
public FilterList DependencyFilterList { get; init; } = null!;
public int DependentFilterListId { get; init; }
public long DependentFilterListId { get; init; }
public FilterList DependentFilterList { get; init; } = null!;
}

View file

@ -0,0 +1,6 @@
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public abstract record Entity
{
public long Id { get; init; }
}

View file

@ -5,10 +5,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterList : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public int LicenseId { get; init; }
public long LicenseId { get; init; }
public License License { get; init; } = null!;
public IEnumerable<FilterListSyntax> FilterListSyntaxes { get; init; } = new HashSet<FilterListSyntax>();
public IEnumerable<FilterListLanguage> FilterListLanguages { get; init; } = new HashSet<FilterListLanguage>();

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListLanguage
{
public int FilterListId { get; init; }
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public string Iso6391 { get; init; } = null!;
public long LanguageId { get; init; }
public Language Language { get; init; } = null!;
}
@ -21,11 +21,7 @@ public virtual void Configure(EntityTypeBuilder<FilterListLanguage> builder)
var nr = new SnakeCaseNameRewriter(CultureInfo.InvariantCulture);
builder.ToTable($"{nr.RewriteName(nameof(FilterListLanguage))}s");
builder.HasKey(fll => new { fll.FilterListId, fll.Iso6391 });
builder.HasOne(fll => fll.Language)
.WithMany(l => l.FilterListLanguages)
.HasForeignKey(fll => fll.Iso6391)
.HasConstraintName("fk_filter_list_languages_languages_iso6391");
builder.HasKey(fll => new { fll.FilterListId, fll.LanguageId });
builder.HasQueryFilter(fll => fll.FilterList.IsApproved && fll.Language.IsApproved);
builder.HasDataJsonFile<FilterListLanguage>();
}

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListMaintainer
{
public int FilterListId { get; init; }
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public int MaintainerId { get; init; }
public long MaintainerId { get; init; }
public Maintainer Maintainer { get; init; } = null!;
}

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListSyntax
{
public int FilterListId { get; init; }
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public int SyntaxId { get; init; }
public long SyntaxId { get; init; }
public Syntax Syntax { get; init; } = null!;
}

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListTag
{
public int FilterListId { get; init; }
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public int TagId { get; init; }
public long TagId { get; init; }
public Tag Tag { get; init; } = null!;
}

View file

@ -7,8 +7,8 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record FilterListViewUrl
{
public int Id { get; init; }
public int FilterListId { get; init; }
public long Id { get; init; }
public long FilterListId { get; init; }
public FilterList FilterList { get; init; } = null!;
public short SegmentNumber { get; init; }
public short Primariness { get; init; }

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Fork
{
public int UpstreamFilterListId { get; init; }
public long UpstreamFilterListId { get; init; }
public FilterList UpstreamFilterList { get; init; } = null!;
public int ForkFilterListId { get; init; }
public long ForkFilterListId { get; init; }
public FilterList ForkFilterList { get; init; } = null!;
}

View file

@ -14,10 +14,11 @@ internal class LanguageTypeConfiguration : AggregateRootTypeConfiguration<Langua
{
public override void Configure(EntityTypeBuilder<Language> builder)
{
builder.HasKey(l => l.Iso6391);
builder.Property(l => l.Iso6391)
.IsFixedLength()
.HasMaxLength(2);
builder.HasIndex(l => l.Iso6391)
.IsUnique();
builder.HasIndex(l => l.Name)
.IsUnique();
builder.HasDataJsonFileAggregate<Language>();

View file

@ -5,7 +5,6 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record License : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public bool PermitsModification { get; init; }

View file

@ -1,11 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Maintainer : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public Uri? Url { get; init; }
public string? EmailAddress { get; init; }

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Merge
{
public int IncludedInFilterListId { get; init; }
public long IncludedInFilterListId { get; init; }
public FilterList IncludedInFilterList { get; init; } = null!;
public int IncludesFilterListId { get; init; }
public long IncludesFilterListId { get; init; }
public FilterList IncludesFilterList { get; init; } = null!;
}

View file

@ -5,7 +5,6 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Software : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? HomeUrl { get; init; }

View file

@ -7,9 +7,9 @@ namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record SoftwareSyntax
{
public int SoftwareId { get; init; }
public long SoftwareId { get; init; }
public Software Software { get; init; } = null!;
public int SyntaxId { get; init; }
public long SyntaxId { get; init; }
public Syntax Syntax { get; init; } = null!;
}

View file

@ -1,11 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Syntax : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public Uri? Url { get; init; }

View file

@ -1,11 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace FilterLists.Directory.Infrastructure.Persistence.Queries.Entities;
public record Tag : AggregateRoot
{
public int Id { get; init; }
public string Name { get; init; } = null!;
public string? Description { get; init; }
public IEnumerable<FilterListTag> FilterListTags { get; init; } = new HashSet<FilterListTag>();