diff --git a/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md new file mode 100644 index 00000000..01a302f8 --- /dev/null +++ b/docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md @@ -0,0 +1,86 @@ +# Architecture Decision Record (ADR): 0020 - Use GUID Version 7 for Persisted Identifiers + +## Status +**Accepted** (2026-11-16) + +## Context + +Persisted entity identifiers were generated with `Guid.NewGuid()`, which produces a version 4 GUID with 122 random bits and no ordering. SQLite stores the identifiers as upper case, hyphenated TEXT values, and the primary key is the index key, so random identifiers scatter inserts across the index instead of appending to it. + +Identifiers are minted in several places: + +- Domain value object factories, mappings, and aggregate methods that create domain event identifiers. +- Application command handlers that build repository entities. +- Data access repositories and the data seed service. +- Infrastructure media library scan jobs, provider configuration storage, scheduler execution, and theme synchronization. +- Entity Framework Core, for keys configured with `ValueGeneratedOnAdd`, including real keys such as `PermissionEntity.Id` and `RoleEntity.Id`, and shadow keys of owned collections such as `AlbumReleaseTypes.Id`. +- Two bulk inserts that generate their identifiers in SQLite to keep a single statement. + +A search for `Guid.NewGuid` cannot see the Entity Framework Core and SQL paths. Those paths would otherwise keep producing version 4 identifiers while the rest of the solution moves to version 7. + +## Decision + +Persisted entity and domain event identifiers are created with `Guid.CreateVersion7()`, which embeds a Unix timestamp in milliseconds in the most significant bits and makes the identifiers time ordered. + +The decision applies to Domain, Application, DataAccess, and Infrastructure: + +- Every identifier factory and every code path that mints an entity or domain event identifier in application code calls `Guid.CreateVersion7()` directly. +- Every Entity Framework Core property of type `Guid` with `ValueGenerated.OnAdd` is assigned the `GuidV7ValueGenerator` in `LuminaDbContext.OnModelCreating`. The loop covers real keys and owned collection shadow keys, so the data seed service can keep leaving seeded permission and role identifiers unset. +- Existing rows keep their version 4 identifiers. This is a forward-only change, and no primary key or foreign key is rewritten. + +The following identifiers intentionally remain outside the version 7 strategy: + +- **Opaque playback delivery handles** in `PlaybackDeliveryHandleService` stay version 4. The handle is deliberately unguessable and must not reveal when it was created, and version 7 embeds the creation time and leaves fewer random bits. +- **Plugin identifiers** in `PluginDetectionSyncJob.DerivePluginId` are derived with SHA-256 from the plugin assembly file name, so a plugin that fails to load keeps the same row across restarts. A derived, stable value is required, not a time ordered one. +- **The SYSTEM audit user identifier** in `UpdateAuditableEntitiesInterceptor` is the fixed sentinel `11111111-1111-1111-1111-111111111111`. +- **The bulk insert paths** in `PlaylistRepository.InsertScopeEntriesAsync` and `LibraryScanSnapshotRepository.ApplySnapshotSwapAsync` generate random version 4 GUIDs in SQLite. Generating the identifiers in C# would materialize the rows and defeat the single statement insert. SQLite cannot produce a version 7 GUID inside those statements without a custom function. +- **Temporary file names, cache reservation and deletion names, theme work directories, and UI script identifiers** are not persisted identifiers, so they stay version 4. + +## Consequences + +### Positive Outcomes + +| Aspect | Benefit | +|---|---| +| Index locality | Time ordered keys append to the primary key index instead of scattering across it | +| Diagnostics | The creation time is recoverable from a persisted identifier | +| Coverage | Entity Framework Core keys and owned collection shadow keys follow the same strategy as the code that assigns identifiers explicitly | +| Consistency | The solution has one strategy for persisted identifiers, with the exceptions recorded above | +| Compatibility | The identifier type and storage format are unchanged, so no schema migration is required | + +### Risks and Tradeoffs + +| Risk | Mitigation Strategy | +|---|---| +| The creation time is embedded in the identifier | Do not use version 7 identifiers where the creation time must remain secret | +| Version 7 has fewer random bits than version 4 | Keep version 4 for opaque security handles, and never treat an identifier as a secret | +| Existing rows keep version 4 identifiers | Do not use identifier order as a chronology across the migration boundary; use `CreatedOnUtc` | +| The two SQL bulk insert paths keep version 4 identifiers | The exception is documented in this ADR and in both repositories, so it is not changed accidentally | +| Version 7 ordering depends on the system clock | Clock skew can break ordering, but not uniqueness; do not depend on strict ordering across machines | +| Entity Framework Core could seed a new key with version 4 again | `LuminaDbContext` applies the generator to every `Guid` property configured with `ValueGenerated.OnAdd`, including owned shadow keys | + +## Alternatives Considered + +### 1. Keep version 4 identifiers + +Keep `Guid.NewGuid()` everywhere and accept random primary key inserts. + +**Rejected**: random keys scatter inserts across the SQLite primary key index, which is the write path of every media library scan and every catalogue edit. + +### 2. Generate sequential or COMB GUIDs in application code + +Implement a custom monotonic GUID generator that places a timestamp or counter in the version 4 layout. + +**Rejected**: it requires custom generation and ordering logic that must be maintained and tested, while .NET provides a standard time ordered version 7 GUID. + +### 3. Generate version 7 identifiers in SQL for the bulk inserts + +Construct the version 7 timestamp and random fields inside the bulk SQL statements. + +**Rejected**: SQLite has no built-in version 7 GUID function, and adding a custom function or extension for these two paths would add deployment and portability constraints. The single statement inserts keep their version 4 identifiers and the exception is documented. + +### 4. Rewrite existing identifiers to version 7 + +Migrate every stored primary key and foreign key to a version 7 value. + +**Rejected**: rewriting primary keys means rewriting every foreign key that references them, with a high risk of corruption and downtime, for no benefit to existing rows. diff --git a/docs/technical/templates/CSharpConventions.md b/docs/technical/templates/CSharpConventions.md index fddac500..45397bf6 100644 --- a/docs/technical/templates/CSharpConventions.md +++ b/docs/technical/templates/CSharpConventions.md @@ -34,6 +34,7 @@ This project enforces many style rules via `.editorconfig` as build errors, so t - **``**: avoid on classes implementing interface members. Developers usually work in the implementing class and should see documentation there directly, without having to open the interface. - **Boolean naming**: boolean fields, properties, and methods returning booleans must start with a verb implying true/false: `is`, `are`, `should`, `has`, `was`, `can`, etc. - **Error handling**: rule violations return `Result`. Never throw exceptions unless explicitly justified (e.g. startup/configuration code). Flag any `throw` outside that context. +- **Identifier generation**: persisted entity and domain event identifiers are created with `Guid.CreateVersion7()`, never `Guid.NewGuid()`, so inserts stay time ordered. Entity Framework Core keys configured with `ValueGeneratedOnAdd` receive the same generator through `LuminaDbContext`. Version 4 remains correct only for opaque security handles, temporary file or cache names, fixed sentinel identifiers such as the SYSTEM audit user, stable derived identifiers such as the SHA-256 plugin identifier, and the SQL bulk insert paths recorded in [ADR-0020](../architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md). ## Review priority diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumMapping.cs index d8eca969..5f101a93 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumMapping.cs @@ -66,7 +66,7 @@ public static class AlbumMapping MusicBrainzReleaseArtistId = domainEntity.MusicBrainzReleaseArtistId.HasValue ? domainEntity.MusicBrainzReleaseArtistId.Value.Value : null, Contributors = [.. domainEntity.Contributors.Select(contributor => new AlbumContributorEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), AlbumId = domainEntity.Id.Value, MediaContributorId = contributor.ContributorId.Value, Role = contributor.Role, diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistMapping.cs index 01e02e5f..92a6ffaf 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistMapping.cs @@ -48,7 +48,7 @@ public static class ArtistMapping Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()], Contributors = [.. domainEntity.Contributors.Select(contributor => new ArtistContributorEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), ArtistId = domainEntity.Id.Value, MediaContributorId = contributor.ContributorId.Value, Role = contributor.Role, diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs index 60efeef1..256f8df1 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs @@ -72,7 +72,7 @@ public static class TrackMapping MusicBrainzWorkId = domainEntity.Work.HasValue ? domainEntity.Work.Value.MusicBrainzWorkId.Value : null, Contributors = [.. domainEntity.Contributors.Select(contributor => new TrackContributorEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), TrackId = domainEntity.Id.Value, MediaContributorId = contributor.ContributorId.Value, Role = contributor.Role, diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs index 37046f65..24bf16b3 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/BookMapping.cs @@ -60,7 +60,7 @@ public static class BookMapping ISBNs = [.. domainEntity.ISBNs.ToRepositoryEntities()], Contributors = [.. domainEntity.Contributors.Select(contributor => new BookContributorEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), BookId = domainEntity.Id.Value, MediaContributorId = contributor.ContributorId.Value, Role = contributor.Role, @@ -115,6 +115,6 @@ public static class BookMapping entity.BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null; entity.AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null; entity.UpdatedOnUtc = DateTime.UtcNow; - entity.UpdatedBy = Guid.NewGuid(); + entity.UpdatedBy = Guid.CreateVersion7(); } } diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/UpdateBookCoverCommandMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/UpdateBookCoverCommandMapping.cs index f28821d0..6e5a810e 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/UpdateBookCoverCommandMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/UpdateBookCoverCommandMapping.cs @@ -29,7 +29,7 @@ public static class UpdateBookCoverCommandMapping { return new BookArtworkEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), BookId = bookId, ArtworkType = ArtworkType.Cover, Ordinal = 0, diff --git a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs index 6b74fee9..8bb12460 100644 --- a/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs +++ b/src/Lumina.Application/Core/Maintenance/ApplicationSetup/Commands/SetupApplication/SetupApplicationCommandHandler.cs @@ -97,7 +97,7 @@ public class SetupApplicationCommandHandler : ICommandHandler addEntryResult = await _unitOfWork.PlaylistRepository .AddEntriesAsync(playlistId, userId, [trackId], PlaylistMediaItemType.MusicTrack, [entryId], updatedOnUtc, cancellationToken).ConfigureAwait(false); diff --git a/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs index 112af453..e2dfc95e 100644 --- a/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs +++ b/src/Lumina.Application/Core/Scheduling/Commands/UpdateSchedulerDisplayPreferences/UpdateSchedulerDisplayPreferencesCommandHandler.cs @@ -67,7 +67,7 @@ public class UpdateSchedulerDisplayPreferencesCommandHandler : ICommandHandler +/// Generates time ordered version 7 GUIDs for identifier properties whose values are assigned by the persistence layer. +/// +public sealed class GuidV7ValueGenerator : ValueGenerator +{ + /// + /// Gets a value indicating whether the generated values are temporary. + /// + /// The generated identifiers are stored permanently, so they are not temporary values. + public override bool GeneratesTemporaryValues => false; + + /// + /// Generates the next time ordered identifier. + /// + /// The tracked entity entry that owns the property. + /// A new version 7 GUID. + public override Guid Next(EntityEntry entry) + { + return Guid.CreateVersion7(); + } +} diff --git a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanSnapshotRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanSnapshotRepository.cs index b3975dd5..995c21b8 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanSnapshotRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryScanSnapshotRepository.cs @@ -105,6 +105,8 @@ internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotReposi // The Id of the inserted rows is generated in SQL as a random 16 byte value formatted as upper case hex (hex(randomblob(16))), which the storage layer parses as a Guid; // generating the Ids in code would defeat the purpose of these single statement bulk inserts. + // These Ids are random version 4 values rather than the version 7 values used elsewhere, because SQLite cannot produce a version 7 GUID + // inside this statement. See docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md for details. // Add an audit entry for every media library scan snapshot item that is no longer present in the current scan, meaning it was deleted from the storage medium. const string AUDIT_DELETED_SQL = """ diff --git a/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs index 93fa1f78..7444c33d 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MediaContributors/MediaContributorRepository.cs @@ -87,7 +87,7 @@ internal sealed class MediaContributorRepository : IMediaContributorRepository MediaContributorEntity contributor = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), DisplayName = displayName, LegalName = legalName, CreatedOnUtc = DateTime.UtcNow, diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicArtworkRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicArtworkRepository.cs index 0fbf50fd..608112c2 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicArtworkRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/MusicArtworkRepository.cs @@ -167,7 +167,7 @@ internal sealed class MusicArtworkRepository : IMusicArtworkRepository { _luminaDbContext.MusicArtwork.Add(new MusicArtworkEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), OwnerType = ownerType, OwnerId = ownerId, ArtworkType = ArtworkType.Cover, diff --git a/src/Lumina.DataAccess/Core/Repositories/Playlists/PlaylistRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Playlists/PlaylistRepository.cs index 1dfec583..1a35e780 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Playlists/PlaylistRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Playlists/PlaylistRepository.cs @@ -517,7 +517,7 @@ internal sealed class PlaylistRepository : IPlaylistRepository if (index > 0) insertSql.Append(", "); insertSql.Append($"(@Id{index}, @PlaylistId{index}, @MediaItemId{index}, @mediaItemType, @Position{index}, @createdOnUtc, @createdBy)"); - Guid entryId = entryIds is null ? Guid.NewGuid() : entryIds[offset + index]; + Guid entryId = entryIds is null ? Guid.CreateVersion7() : entryIds[offset + index]; parameters.Add($"Id{index}", ToStorageId(entryId)); parameters.Add($"PlaylistId{index}", playlistIdText); parameters.Add($"MediaItemId{index}", ToStorageId(mediaItemIds[offset + index])); @@ -562,6 +562,8 @@ internal sealed class PlaylistRepository : IPlaylistRepository { // The entry Ids are generated by SQLite in the same upper case, hyphenated TEXT form the Entity Framework provider stores. Generating // them inside the statement is what lets the scope stay a single insert instead of being materialized in C# just to assign Ids. + // They are random version 4 values rather than the version 7 values used elsewhere, because SQLite cannot produce a version 7 GUID + // inside this statement. See docs/technical/architecture/architecture-knowledge-management/architecture-decision-log/architecture-decision-record-0020.md for details. // The positions are computed by the same ordering the artist and album pages use, so the playlist receives catalogue order directly. // ROW_NUMBER() produces the dense rank, and multiplying it by POSITION_STEP keeps the stored keys sparse. StringBuilder insertSql = new(""" diff --git a/src/Lumina.DataAccess/Core/Seed/DataSeedService.cs b/src/Lumina.DataAccess/Core/Seed/DataSeedService.cs index 8a2c29f6..f34319c8 100644 --- a/src/Lumina.DataAccess/Core/Seed/DataSeedService.cs +++ b/src/Lumina.DataAccess/Core/Seed/DataSeedService.cs @@ -229,7 +229,7 @@ public class DataSeedService : IDataSeedService { return new ScheduledJobEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), Name = name, TaskType = taskType, ScheduleType = scheduleType, diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs index 8ae80df5..41854ac6 100644 --- a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs +++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs @@ -11,7 +11,10 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins; using Lumina.Application.Common.DataAccess.Entities.Scheduling; using Lumina.Application.Common.DataAccess.Entities.Themes; using Lumina.Application.Common.DataAccess.Entities.UsersManagement; +using Lumina.DataAccess.Common.ValueGeneration; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using System; #endregion namespace Lumina.DataAccess.Core.UoW; @@ -210,6 +213,14 @@ public class LuminaDbContext : DbContext // Find all the entity configurations in the assembly and apply them. modelBuilder.ApplyConfigurationsFromAssembly(typeof(LuminaDbContext).Assembly); + // The relational provider seeds its Guid value generators from Guid.NewGuid, so replace them with a time ordered generator for every + // identifier that the persistence layer assigns itself. This covers real keys, such as PermissionEntity.Id, and the shadow keys of + // owned collections, such as AlbumReleaseTypes.Id. + foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes()) + foreach (IMutableProperty property in entityType.GetProperties()) + if (property.ClrType == typeof(Guid) && property.ValueGenerated == ValueGenerated.OnAdd) + property.SetValueGeneratorFactory((generatedProperty, declaringType) => new GuidV7ValueGenerator()); + base.OnModelCreating(modelBuilder); } } diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs index 7e89ed9f..eee1cb42 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs @@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId /// The created instance. public static LibraryId CreateUnique() { - return new LibraryId(Guid.NewGuid()); + return new LibraryId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs index 28fe2ebb..0d02f7da 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs @@ -27,7 +27,7 @@ public sealed class MediaContributorId : EntityId /// The created instance. public static MediaContributorId CreateUnique() { - return new MediaContributorId(Guid.NewGuid()); + return new MediaContributorId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/AlbumId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/AlbumId.cs index 94440675..b2387515 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/AlbumId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/AlbumId.cs @@ -27,7 +27,7 @@ public sealed class AlbumId : EntityId /// The created instance. public static AlbumId CreateUnique() { - return new AlbumId(Guid.NewGuid()); + return new AlbumId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/ArtistId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/ArtistId.cs index 6cd270c4..2a193194 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/ArtistId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/ArtistId.cs @@ -27,7 +27,7 @@ public sealed class ArtistId : EntityId /// The created instance. public static ArtistId CreateUnique() { - return new ArtistId(Guid.NewGuid()); + return new ArtistId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/TrackId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/TrackId.cs index 17e7e1e6..e62ccca6 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/TrackId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/TrackId.cs @@ -27,7 +27,7 @@ public sealed class TrackId : EntityId /// The created instance. public static TrackId CreateUnique() { - return new TrackId(Guid.NewGuid()); + return new TrackId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs index ae51d775..5a856837 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs @@ -27,7 +27,7 @@ public sealed class MediaItemId : EntityId /// The created instance. public static MediaItemId CreateUnique() { - return new MediaItemId(Guid.NewGuid()); + return new MediaItemId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs index c39f4000..b530439d 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs @@ -27,7 +27,7 @@ public sealed class UserId : EntityId /// The created instance. public static UserId CreateUnique() { - return new UserId(Guid.NewGuid()); + return new UserId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/Favorite.cs b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/Favorite.cs index a8b15f6e..b587290b 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/Favorite.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/Favorite.cs @@ -89,7 +89,7 @@ public sealed class Favorite : AggregateRoot Optional.None()); favorite._domainEvents.Add(new FavoriteAddedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), favorite.Id, userId, mediaItemId, @@ -135,7 +135,7 @@ public sealed class Favorite : AggregateRoot _domainEvents.Clear(); IsRemoved = true; _domainEvents.Add(new FavoriteRemovedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, MediaItemId, diff --git a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/ValueObjects/FavoriteId.cs b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/ValueObjects/FavoriteId.cs index d2e89791..495d6834 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/ValueObjects/FavoriteId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FavoriteBoundedContext/FavoriteAggregate/ValueObjects/FavoriteId.cs @@ -27,7 +27,7 @@ public sealed class FavoriteId : EntityId /// The created instance. public static FavoriteId CreateUnique() { - return new FavoriteId(Guid.NewGuid()); + return new FavoriteId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs index 5f3d7344..6aeb5622 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs @@ -289,7 +289,7 @@ public class Library : AggregateRoot /// public void Save() { - _domainEvents.Add(new LibrarySavedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow)); + _domainEvents.Add(new LibrarySavedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow)); } /// @@ -312,7 +312,7 @@ public class Library : AggregateRoot // Only add the delete event if it has not been added already. if (!_domainEvents.Any(domainEvent => domainEvent is LibraryDeletedDomainEvent)) - _domainEvents.Add(new LibraryDeletedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow)); + _domainEvents.Add(new LibraryDeletedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow)); // TODO: perhaps trigger events for removing content related to the removed library (media metadata, etc.). return Result.Deleted; diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryId.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryId.cs index dbf0610d..8c18a013 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryId.cs @@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId /// The created instance. public static LibraryId CreateUnique() { - return new LibraryId(Guid.NewGuid()); + return new LibraryId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/LibraryScan.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/LibraryScan.cs index 40aa22fa..e6210c7d 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/LibraryScan.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/LibraryScan.cs @@ -94,7 +94,7 @@ public class LibraryScan : AggregateRoot if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending)) return Errors.LibraryScanning.LibraryAlreadyBeingScanned; - _domainEvents.Add(new LibraryScanQueuedDomainEvent(Guid.NewGuid(), Id, UserId, LibraryId, DateTime.UtcNow)); + _domainEvents.Add(new LibraryScanQueuedDomainEvent(Guid.CreateVersion7(), Id, UserId, LibraryId, DateTime.UtcNow)); return Result.Success; } @@ -114,7 +114,7 @@ public class LibraryScan : AggregateRoot if (_pastScans.Any(libraryScan => libraryScan.Status == LibraryScanJobStatus.Running || libraryScan.Status == LibraryScanJobStatus.Pending)) return Errors.LibraryScanning.LibraryAlreadyBeingScanned; - _domainEvents.Add(new LibraryScanStartedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow)); + _domainEvents.Add(new LibraryScanStartedDomainEvent(Guid.CreateVersion7(), this, DateTime.UtcNow)); return Result.Success; } @@ -145,7 +145,7 @@ public class LibraryScan : AggregateRoot else return Errors.LibraryScanning.CanOnlyCancelPendingOrRunningScans; - _domainEvents.Add(new LibraryScanCancelledDomainEvent(Guid.NewGuid(), Id, LibraryId, DateTime.UtcNow)); + _domainEvents.Add(new LibraryScanCancelledDomainEvent(Guid.CreateVersion7(), Id, LibraryId, DateTime.UtcNow)); return Result.Success; } diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ScanId.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ScanId.cs index 411eb967..9daa7986 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ScanId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ScanId.cs @@ -27,7 +27,7 @@ public sealed class ScanId : EntityId /// The created instance. public static ScanId CreateUnique() { - return new ScanId(Guid.NewGuid()); + return new ScanId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs index 0cc2d6b7..c16054c3 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs @@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId /// The created instance. public static LibraryId CreateUnique() { - return new LibraryId(Guid.NewGuid()); + return new LibraryId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs index 6232478f..f889672f 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs @@ -27,7 +27,7 @@ public sealed class MediaItemId : EntityId /// The created instance. public static MediaItemId CreateUnique() { - return new MediaItemId(Guid.NewGuid()); + return new MediaItemId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs index 1237c088..8c526da9 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs @@ -27,7 +27,7 @@ public sealed class UserId : EntityId /// The created instance. public static UserId CreateUnique() { - return new UserId(Guid.NewGuid()); + return new UserId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/MediaConsumptionRecord.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/MediaConsumptionRecord.cs index 2dd64891..9ddd87a8 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/MediaConsumptionRecord.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/MediaConsumptionRecord.cs @@ -171,7 +171,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot.Some(occurredOnUtc); _domainEvents.Add(new MediaConsumptionProgressedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, LibraryId, @@ -393,7 +393,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot.Some(occurredOnUtc); _domainEvents.Add(new MediaConsumptionCompletedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, LibraryId, @@ -445,7 +445,7 @@ public sealed class MediaConsumptionRecord : AggregateRoot.Some(occurredOnUtc); _domainEvents.Add(new MediaConsumptionStoppedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, LibraryId, diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/ValueObjects/MediaConsumptionRecordId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/ValueObjects/MediaConsumptionRecordId.cs index 8b219eb2..a6b879a1 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/ValueObjects/MediaConsumptionRecordId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaConsumptionRecordAggregate/ValueObjects/MediaConsumptionRecordId.cs @@ -27,7 +27,7 @@ public sealed class MediaConsumptionRecordId : EntityId /// The created instance. public static MediaConsumptionRecordId CreateUnique() { - return new MediaConsumptionRecordId(Guid.NewGuid()); + return new MediaConsumptionRecordId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaResumePointAggregate/ValueObjects/MediaResumePointId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaResumePointAggregate/ValueObjects/MediaResumePointId.cs index 4e24a555..49a71750 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaResumePointAggregate/ValueObjects/MediaResumePointId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaConsumptionBoundedContext/MediaResumePointAggregate/ValueObjects/MediaResumePointId.cs @@ -27,7 +27,7 @@ public sealed class MediaResumePointId : EntityId /// The created instance. public static MediaResumePointId CreateUnique() { - return new MediaResumePointId(Guid.NewGuid()); + return new MediaResumePointId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/MediaContributorBoundedContext/MediaContributorAggregate/ValueObjects/MediaContributorId.cs b/src/Lumina.Domain/Core/BoundedContexts/MediaContributorBoundedContext/MediaContributorAggregate/ValueObjects/MediaContributorId.cs index 3c4b7a2a..83caa012 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/MediaContributorBoundedContext/MediaContributorAggregate/ValueObjects/MediaContributorId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/MediaContributorBoundedContext/MediaContributorAggregate/ValueObjects/MediaContributorId.cs @@ -26,7 +26,7 @@ public sealed class MediaContributorId : EntityId public static MediaContributorId CreateUnique() { // TODO: enforce invariants. - return new MediaContributorId(Guid.NewGuid()); + return new MediaContributorId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs index 37adf434..0d40129d 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/MediaLibraryBoundedContext/MediaItemAggregate/MediaItemId.cs @@ -30,7 +30,7 @@ public sealed class MediaItemId : EntityId /// The created instance. public static MediaItemId CreateUnique() { - return new MediaItemId(Guid.NewGuid()); + return new MediaItemId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs index 1104b077..e5b95c92 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs @@ -27,7 +27,7 @@ public sealed class UserId : EntityId /// The created instance. public static UserId CreateUnique() { - return new UserId(Guid.NewGuid()); + return new UserId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/Playlist.cs b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/Playlist.cs index b18e7986..d653c67e 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/Playlist.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/Playlist.cs @@ -108,7 +108,7 @@ public sealed class Playlist : AggregateRoot Optional.None()); playlist._domainEvents.Add(new PlaylistCreatedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), playlist.Id, userId, name, @@ -168,7 +168,7 @@ public sealed class Playlist : AggregateRoot Description = description; DateTime occurredOnUtc = DateTime.UtcNow; _domainEvents.Add(new PlaylistDetailsUpdatedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, name, @@ -189,7 +189,7 @@ public sealed class Playlist : AggregateRoot _domainEvents.Clear(); IsDeleted = true; _domainEvents.Add(new PlaylistDeletedDomainEvent( - Guid.NewGuid(), + Guid.CreateVersion7(), Id, UserId, DateTime.UtcNow)); diff --git a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistEntryId.cs b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistEntryId.cs index 18378ef6..7f5b8e8a 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistEntryId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistEntryId.cs @@ -27,7 +27,7 @@ public sealed class PlaylistEntryId : EntityId /// The created instance. public static PlaylistEntryId CreateUnique() { - return new PlaylistEntryId(Guid.NewGuid()); + return new PlaylistEntryId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistId.cs b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistId.cs index 786941bb..e12b4db6 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/PlaylistBoundedContext/PlaylistAggregate/ValueObjects/PlaylistId.cs @@ -27,7 +27,7 @@ public sealed class PlaylistId : EntityId /// The created instance. public static PlaylistId CreateUnique() { - return new PlaylistId(Guid.NewGuid()); + return new PlaylistId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs index 271b3e7e..b8a36aad 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ExternalIdentifiers/UserManagementBoundedContext/UserAggregate/UserId.cs @@ -27,7 +27,7 @@ public sealed class UserId : EntityId /// The created instance. public static UserId CreateUnique() { - return new UserId(Guid.NewGuid()); + return new UserId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ScheduledJob.cs b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ScheduledJob.cs index 067f5fdc..8ad52c60 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ScheduledJob.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ScheduledJob.cs @@ -125,7 +125,7 @@ public class ScheduledJob : AggregateRoot { if (Status != ScheduledJobStatus.Added) return Errors.Scheduling.ScheduledJobCycleAlreadyStarted; - _domainEvents.Add(new ScheduledJobAddedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobAddedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); return Result.Success; } @@ -139,7 +139,7 @@ public class ScheduledJob : AggregateRoot return Errors.Scheduling.ScheduledJobCycleAlreadyStarted; Status = ScheduledJobStatus.Active; - _domainEvents.Add(new ScheduledJobCycleStartedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobCycleStartedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); return Result.Success; } @@ -159,10 +159,10 @@ public class ScheduledJob : AggregateRoot if (previousStatus == ScheduledJobStatus.Running) { LastCompletedOnUtc = Optional.Some(DateTime.UtcNow); - _domainEvents.Add(new ScheduledJobExecutionStoppedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobExecutionStoppedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); } else - _domainEvents.Add(new ScheduledJobCycleStoppedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobCycleStoppedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); return Result.Success; } @@ -174,7 +174,7 @@ public class ScheduledJob : AggregateRoot { if (Status == ScheduledJobStatus.Running) return Errors.Scheduling.ScheduledJobAlreadyRunning; - _domainEvents.Add(new ScheduledJobFiredDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobFiredDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); return Result.Success; } @@ -184,7 +184,7 @@ public class ScheduledJob : AggregateRoot /// An representing either a successful operation, or an error. public Result Remove() { - _domainEvents.Add(new ScheduledJobRemovedDomainEvent(Guid.NewGuid(), Id, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobRemovedDomainEvent(Guid.CreateVersion7(), Id, DateTime.UtcNow)); return Result.Success; } @@ -198,11 +198,11 @@ public class ScheduledJob : AggregateRoot if (Status == ScheduledJobStatus.Running) return Errors.Scheduling.ScheduledJobAlreadyRunning; - Guid runId = Guid.NewGuid(); + Guid runId = Guid.CreateVersion7(); _currentExecutionRunId = Optional.Some(runId); Status = ScheduledJobStatus.Running; LastStartedOnUtc = Optional.Some(DateTime.UtcNow); - _domainEvents.Add(new ScheduledJobExecutionStartedDomainEvent(Guid.NewGuid(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobExecutionStartedDomainEvent(Guid.CreateVersion7(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow)); return Result.Success; } @@ -223,7 +223,7 @@ public class ScheduledJob : AggregateRoot // A cycle run returns the scheduled job to its active state, where it waits for the next execution; a one time execution finishes the scheduled job. Status = isCycleRun ? ScheduledJobStatus.Active : ScheduledJobStatus.Completed; LastCompletedOnUtc = Optional.Some(DateTime.UtcNow); - _domainEvents.Add(new ScheduledJobExecutionCompletedDomainEvent(Guid.NewGuid(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow)); + _domainEvents.Add(new ScheduledJobExecutionCompletedDomainEvent(Guid.CreateVersion7(), Id, runId, TaskType, isCycleRun, DateTime.UtcNow)); return Result.Success; } } diff --git a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ValueObjects/ScheduledJobId.cs b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ValueObjects/ScheduledJobId.cs index c6dcbdce..ac5db4e5 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ValueObjects/ScheduledJobId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/SchedulingBoundedContext/ScheduledJobAggregate/ValueObjects/ScheduledJobId.cs @@ -27,7 +27,7 @@ public sealed class ScheduledJobId : EntityId /// The created instance. public static ScheduledJobId CreateUnique() { - return new ScheduledJobId(Guid.NewGuid()); + return new ScheduledJobId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserAggregate/ValueObjects/UserId.cs b/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserAggregate/ValueObjects/UserId.cs index f7f1820b..3e0aec48 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserAggregate/ValueObjects/UserId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserAggregate/ValueObjects/UserId.cs @@ -27,7 +27,7 @@ public sealed class UserId : EntityId /// The created instance. public static UserId CreateUnique() { - return new UserId(Guid.NewGuid()); + return new UserId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserSettingsAggregate/ValueObjects/UserSettingsId.cs b/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserSettingsAggregate/ValueObjects/UserSettingsId.cs index 0be71a4a..b9abc168 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserSettingsAggregate/ValueObjects/UserSettingsId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/UserManagementBoundedContext/UserSettingsAggregate/ValueObjects/UserSettingsId.cs @@ -27,7 +27,7 @@ public sealed class UserSettingsId : EntityId /// The created instance. public static UserSettingsId CreateUnique() { - return new UserSettingsId(Guid.NewGuid()); + return new UserSettingsId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/MovieLibraryAggregate/ValueObjects/MovieId.cs b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/MovieLibraryAggregate/ValueObjects/MovieId.cs index 9ee09dd2..bde60af0 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/MovieLibraryAggregate/ValueObjects/MovieId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/MovieLibraryAggregate/ValueObjects/MovieId.cs @@ -28,7 +28,7 @@ public sealed class MovieId : EntityId public static MovieId CreateUnique() { // TODO: enforce invariants. - return new MovieId(Guid.NewGuid()); + return new MovieId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs index 8d24259a..99e5c79f 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs @@ -26,7 +26,7 @@ public sealed class EpisodeId : EntityId public static EpisodeId CreateUnique() { // TODO: enforce invariants. - return new EpisodeId(Guid.NewGuid()); + return new EpisodeId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/SeasonId.cs b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/SeasonId.cs index a8796c2d..ea4419b2 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/SeasonId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/SeasonId.cs @@ -26,7 +26,7 @@ public sealed class SeasonId : EntityId public static SeasonId CreateUnique() { // TODO: enforce invariants. - return new SeasonId(Guid.NewGuid()); + return new SeasonId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/TvShowId.cs b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/TvShowId.cs index 4de48b35..244f47a3 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/TvShowId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/VideoLibraryBoundedContext/TvShowLibraryAggregate/ValueObjects/TvShowId.cs @@ -26,7 +26,7 @@ public sealed class TvShowId : EntityId public static TvShowId CreateUnique() { // TODO: enforce invariants. - return new TvShowId(Guid.NewGuid()); + return new TvShowId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookId.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookId.cs index 89b79e8e..4aec8310 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookId.cs @@ -27,7 +27,7 @@ public sealed class BookId : EntityId /// The created instance. public static BookId CreateUnique() { - return new BookId(Guid.NewGuid()); + return new BookId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookSeriesId.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookSeriesId.cs index 4027baf6..0e47d833 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookSeriesId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/ValueObjects/BookSeriesId.cs @@ -33,7 +33,7 @@ public sealed class BookSeriesId : ValueObject /// The created instance. public static BookSeriesId CreateUnique() { - return new BookSeriesId(Guid.NewGuid()); + return new BookSeriesId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs index 126f2b82..d46f6e7b 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/LibraryManagementBoundedContext/LibraryAggregate/LibraryId.cs @@ -27,7 +27,7 @@ public sealed class LibraryId : EntityId /// The created instance. public static LibraryId CreateUnique() { - return new LibraryId(Guid.NewGuid()); + return new LibraryId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs index 4cb22126..140b3efe 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/ExternalIdentifiers/MediaContributorBoundedContext/MediaContributorAggregate/MediaContributorId.cs @@ -27,7 +27,7 @@ public sealed class MediaContributorId : EntityId /// The created instance. public static MediaContributorId CreateUnique() { - return new MediaContributorId(Guid.NewGuid()); + return new MediaContributorId(Guid.CreateVersion7()); } /// diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/AudioLibrary/MusicLibrary/Playback/PlaybackDeliveryHandleService.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/AudioLibrary/MusicLibrary/Playback/PlaybackDeliveryHandleService.cs index 1ae2e490..44ee40a2 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/AudioLibrary/MusicLibrary/Playback/PlaybackDeliveryHandleService.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/AudioLibrary/MusicLibrary/Playback/PlaybackDeliveryHandleService.cs @@ -61,6 +61,7 @@ internal sealed class PlaybackDeliveryHandleService : IPlaybackDeliveryHandleSer EnforceGlobalLimit(); // The handle is a random opaque value, not a derived one, so it cannot be computed from the track or the file by a caller. + // It stays a version 4 GUID on purpose: version 7 embeds the creation time and leaves fewer random bits for an unguessable handle. string deliveryId = Guid.NewGuid().ToString("N"); DateTimeOffset expiresAtUtc = now.Add(s_deliveryLifetime); _deliveries[deliveryId] = new StoredDelivery(delivery, signature, expiresAtUtc); diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicFileSystemDiscoveryJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicFileSystemDiscoveryJob.cs index 504ddd30..e11b5076 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicFileSystemDiscoveryJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicFileSystemDiscoveryJob.cs @@ -169,7 +169,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF } // This job finished, increment the number of processed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // Call each linked child with the obtained payload. @@ -248,7 +248,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF fingerprintBatch.Add(new DirectoryScanFingerprintEntity() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = LibraryId.Value, Path = currentDirectory.Path, LastWriteTimeUtc = currentLastWriteTimeUtc @@ -386,7 +386,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF return new LibraryScanStagingResultsEntity() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryScanId = ScanId.Value, Path = filePath.Path, Size = size, @@ -414,7 +414,7 @@ internal sealed class MusicFileSystemDiscoveryJob : MediaLibraryScanJob, IMusicF return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs index 849be525..eee37a9d 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs @@ -626,7 +626,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr { return new MusicArtworkEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), OwnerType = ownerType, OwnerId = ownerId, ArtworkType = artworkType, @@ -659,7 +659,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanItemMaterializer.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanItemMaterializer.cs index 8ef1be2f..13ae06e0 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanItemMaterializer.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanItemMaterializer.cs @@ -257,7 +257,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI { return new ArtistEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, Name = name, MusicBrainzArtistId = musicBrainzArtistId, @@ -284,7 +284,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI MusicLibraryScanItemMetadataEntity firstStagedItem = stagedItems[0]; return new AlbumEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), ArtistId = artistId, LibraryId = libraryId, Title = title, @@ -311,7 +311,7 @@ internal sealed class MusicMediaLibraryScanItemMaterializer : IMediaLibraryScanI { return new TrackEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), AlbumId = albumId, LibraryId = libraryId, Path = stagedItem.Path, diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanMetadataEnricher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanMetadataEnricher.cs index 85daaa66..dbebb795 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanMetadataEnricher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanMetadataEnricher.cs @@ -586,7 +586,7 @@ internal sealed class MusicMediaLibraryScanMetadataEnricher : IMediaLibraryScanM return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMetadataExtractionJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMetadataExtractionJob.cs index 500fe710..209ce725 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMetadataExtractionJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMetadataExtractionJob.cs @@ -154,7 +154,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe } // This job finished, increment the number of processed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // Call each linked child with the obtained payload. @@ -319,7 +319,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe return new MusicLibraryScanItemMetadataEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryScanId = ScanId.Value, LibraryId = LibraryId.Value, Path = path, @@ -563,7 +563,7 @@ internal sealed class MusicMetadataExtractionJob : MediaLibraryScanJob, IMusicMe return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanArtworkEnrichmentJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanArtworkEnrichmentJob.cs index ed044244..7694defa 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanArtworkEnrichmentJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanArtworkEnrichmentJob.cs @@ -76,11 +76,11 @@ internal sealed class MediaLibraryScanArtworkEnrichmentJob : MediaLibraryScanJob await artworkEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false); // Increment the number of completed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed. if (Children.Count == 0) - await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // Call each linked child with the obtained payload. foreach (IMediaLibraryScanJob child in Children) diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs index fb7b7526..239d010f 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanDiffJob.cs @@ -76,7 +76,7 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); // This job finished, increment the number of processed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // Call each linked child with the obtained payload. @@ -112,7 +112,7 @@ internal sealed class MediaLibraryScanDiffJob : MediaLibraryScanJob, IMediaLibra return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs index b0b76b80..4fd265cf 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanHashJob.cs @@ -132,7 +132,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra } // This job finished, increment the number of processed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // Call each linked child with the obtained payload. @@ -168,7 +168,7 @@ internal sealed class MediaLibraryScanHashJob : MediaLibraryScanJob, IMediaLibra return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs index 41e9e3c2..6ee2b8a6 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanMetadataEnrichmentJob.cs @@ -76,11 +76,11 @@ internal sealed class MediaLibraryScanMetadataEnrichmentJob : MediaLibraryScanJo await metadataEnricher.EnrichAsync(LibraryId, ScanId, UserId, cancellationToken).ConfigureAwait(false); // Increment the number of completed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed. if (Children.Count == 0) - await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // Call each linked child with the obtained payload. foreach (IMediaLibraryScanJob child in Children) diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanProviderConfigurationInvalidationJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanProviderConfigurationInvalidationJob.cs index 8891a703..4d776e9a 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanProviderConfigurationInvalidationJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanProviderConfigurationInvalidationJob.cs @@ -147,7 +147,7 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med library.ArtworkProvidersConfigurationFingerprint = artworkFingerprint; library.PathTemplateFingerprint = pathTemplateFingerprint; library.UpdatedOnUtc = DateTime.UtcNow; - library.UpdatedBy = Guid.NewGuid(); + library.UpdatedBy = Guid.CreateVersion7(); Result saveChangesResult = await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false); if (saveChangesResult.IsFailure) @@ -159,11 +159,11 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); // Increment the number of completed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed. if (Children.Count == 0) - await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // Call each linked child with the obtained payload. foreach (IMediaLibraryScanJob child in Children) @@ -198,7 +198,7 @@ internal sealed class MediaLibraryScanProviderConfigurationInvalidationJob : Med return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs index 8e9cfe60..86becfb0 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/MediaLibraryScanResultsSaveJob.cs @@ -106,7 +106,7 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed foreach (string deletedPath in getDeletedPathsResult.Value) { cancellationToken.ThrowIfCancellationRequested(); - await domainEventPublisher.PublishAsync(new LibraryMediaItemDeletedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryMediaItemDeletedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, deletedPath, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); } // Materialize the media library items from the scan snapshot, so that they are browsable even without web metadata. @@ -133,11 +133,11 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed throw new InvalidOperationException(publishJobProgressResult.FirstError.Description); // Increment the number of completed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // When this job has no linked children, it is the last job in the directed acyclic job graph, and the scan is completed. if (Children.Count == 0) - await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.NewGuid(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFinishedDomainEvent(Guid.CreateVersion7(), compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); // Call each linked child with the obtained payload. foreach (IMediaLibraryScanJob child in Children) @@ -171,7 +171,7 @@ internal sealed class MediaLibraryScanResultsSaveJob : MediaLibraryScanJob, IMed if (scanJobProgressResult.IsFailure) return scanJobProgressResult.Errors; - await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs index 42f35c39..6d469f6c 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Common/ScanFailurePublisher.cs @@ -32,7 +32,7 @@ internal static class ScanFailurePublisher { await using AsyncServiceScope asyncServiceScope = serviceScopeFactory.CreateAsyncScope(); IDomainEventPublisher domainEventPublisher = asyncServiceScope.ServiceProvider.GetService()!; - await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.NewGuid(), libraryId, compositeKey, DateTime.UtcNow, Optional.FromNullable(exception.Message)), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanFailedDomainEvent(Guid.CreateVersion7(), libraryId, compositeKey, DateTime.UtcNow, Optional.FromNullable(exception.Message)), cancellationToken).ConfigureAwait(false); } catch { diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs index c104be28..09735d8c 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksFileSystemDiscoveryJob.cs @@ -170,7 +170,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF } // This job finished, increment the number of processed jobs progress. - await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + await domainEventPublisher.PublishAsync(new LibraryScanProgressChangedDomainEvent(Guid.CreateVersion7(), LibraryId, compositeKey, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); Status = LibraryScanJobStatus.Completed; // Call each linked child with the obtained payload. @@ -237,7 +237,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF fingerprintBatch.Add(new DirectoryScanFingerprintEntity() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = LibraryId.Value, Path = currentDirectory.FullName, LastWriteTimeUtc = currentLastWriteTimeUtc @@ -389,7 +389,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF { return new LibraryScanStagingResultsEntity() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryScanId = ScanId.Value, Path = file.FullName, Size = file.Length, @@ -417,7 +417,7 @@ internal sealed class BooksFileSystemDiscoveryJob : MediaLibraryScanJob, IBooksF return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), LibraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanArtworkEnricher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanArtworkEnricher.cs index 51953e6a..e46f3af0 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanArtworkEnricher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanArtworkEnricher.cs @@ -210,7 +210,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr { coverArtwork.Status = ArtworkStatus.Failed; coverArtwork.UpdatedOnUtc = DateTime.UtcNow; - coverArtwork.UpdatedBy = Guid.NewGuid(); + coverArtwork.UpdatedBy = Guid.CreateVersion7(); } return; } @@ -240,7 +240,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr { existingCoverArtwork.Status = ArtworkStatus.Failed; existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow; - existingCoverArtwork.UpdatedBy = Guid.NewGuid(); + existingCoverArtwork.UpdatedBy = Guid.CreateVersion7(); } return; } @@ -262,7 +262,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr existingCoverArtwork.Provider = resolvedArtwork.ProviderName; existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow; existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow; - existingCoverArtwork.UpdatedBy = Guid.NewGuid(); + existingCoverArtwork.UpdatedBy = Guid.CreateVersion7(); } } else @@ -272,7 +272,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr existingCoverArtwork.Provider = resolvedArtwork.ProviderName; existingCoverArtwork.LastUpdateUtc = DateTime.UtcNow; existingCoverArtwork.UpdatedOnUtc = DateTime.UtcNow; - existingCoverArtwork.UpdatedBy = Guid.NewGuid(); + existingCoverArtwork.UpdatedBy = Guid.CreateVersion7(); } } @@ -332,7 +332,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr { return new BookArtworkEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), BookId = bookId, ArtworkType = ArtworkType.Cover, Ordinal = 0, @@ -364,7 +364,7 @@ internal sealed class BooksMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanItemMaterializer.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanItemMaterializer.cs index de677c7d..c883f9f7 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanItemMaterializer.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanItemMaterializer.cs @@ -171,7 +171,7 @@ internal sealed class BooksMediaLibraryScanItemMaterializer : IMediaLibraryScanI return new BookEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = library.Id.Value, Path = path, Title = title, diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanMetadataEnricher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanMetadataEnricher.cs index b569ff8b..7c400269 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanMetadataEnricher.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/WrittenContent/Books/BooksMediaLibraryScanMetadataEnricher.cs @@ -221,7 +221,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM // No metadata provider returned usable metadata, so the book is marked as failed to enrich, keeping its previous metadata. bookEntity.MetadataStatus = MetadataStatus.Failed; bookEntity.UpdatedOnUtc = DateTime.UtcNow; - bookEntity.UpdatedBy = Guid.NewGuid(); + bookEntity.UpdatedBy = Guid.CreateVersion7(); return; } @@ -244,7 +244,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM continue; linkedContributors.Add(new BookContributorEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), BookId = bookEntity.Id, MediaContributorId = contributorEntity.Id, Role = role, @@ -395,7 +395,7 @@ internal sealed class BooksMediaLibraryScanMetadataEnricher : IMediaLibraryScanM return scanJobProgressResult.Errors; await domainEventPublisher.PublishAsync(new LibraryScanJobProgressChangedDomainEvent( - Guid.NewGuid(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); + Guid.CreateVersion7(), libraryId, compositeKey, scanJobProgressResult.Value, DateTime.UtcNow), cancellationToken).ConfigureAwait(false); return Result.Success; } diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Queue/MediaLibraryScanProcessorJob.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Queue/MediaLibraryScanProcessorJob.cs index 25650cea..e09f01d2 100644 --- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Queue/MediaLibraryScanProcessorJob.cs +++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Queue/MediaLibraryScanProcessorJob.cs @@ -146,7 +146,7 @@ internal sealed class MediaLibraryScanProcessorJob : BackgroundService // The file system discovery job is the only top level job of the scan job graph, and every job awaits its children, so awaiting it // completes the entire scan. The next queued scan is only dequeued once this call returns. - await rootJob.ExecuteAsync(Guid.NewGuid(), new { }, linkedSource.Token).ConfigureAwait(false); + await rootJob.ExecuteAsync(Guid.CreateVersion7(), new { }, linkedSource.Token).ConfigureAwait(false); _logger.LogInformation("Completed the media library scan '{ScanId}' of the media library '{LibraryId}'.", compositeId.ScanId.Value, libraryScan.LibraryId.Value); } diff --git a/src/Lumina.Infrastructure/Core/Plugins/MediaLibraryProviderConfigurationStore.cs b/src/Lumina.Infrastructure/Core/Plugins/MediaLibraryProviderConfigurationStore.cs index debdadd7..f63ad0d8 100644 --- a/src/Lumina.Infrastructure/Core/Plugins/MediaLibraryProviderConfigurationStore.cs +++ b/src/Lumina.Infrastructure/Core/Plugins/MediaLibraryProviderConfigurationStore.cs @@ -291,7 +291,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryBookReaderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -333,7 +333,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryBookReaderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -384,7 +384,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // the audit columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryMetadataProviderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -437,7 +437,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // audit columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryArtworkProviderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -479,7 +479,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // the audit columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryMetadataProviderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -521,7 +521,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv // audit columns are left at their defaults because the persistence layer stamps them when the row is saved. LibraryArtworkProviderConfigurationEntity configuration = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = false, @@ -578,7 +578,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false; LibraryMetadataProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryMetadataProviderConfigurationEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = isEnabled, @@ -636,7 +636,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false; LibraryArtworkProviderConfigurationEntity configuration = storedConfiguration ?? new LibraryArtworkProviderConfigurationEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = isEnabled, @@ -693,7 +693,7 @@ internal sealed class MediaLibraryProviderConfigurationStore : IMediaLibraryProv bool isEnabled = enabledStatesByPluginId.GetValueOrDefault(pluginId) ?? storedConfiguration?.IsEnabled ?? false; LibraryBookReaderConfigurationEntity configuration = storedConfiguration ?? new LibraryBookReaderConfigurationEntity { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), LibraryId = libraryId, PluginId = pluginId, IsEnabled = isEnabled, diff --git a/src/Lumina.Infrastructure/Core/Scheduling/Execution/ScheduledJobSchedulerJob.cs b/src/Lumina.Infrastructure/Core/Scheduling/Execution/ScheduledJobSchedulerJob.cs index 1b6cb328..ac53723a 100644 --- a/src/Lumina.Infrastructure/Core/Scheduling/Execution/ScheduledJobSchedulerJob.cs +++ b/src/Lumina.Infrastructure/Core/Scheduling/Execution/ScheduledJobSchedulerJob.cs @@ -184,7 +184,7 @@ public sealed class ScheduledJobSchedulerJob : BackgroundService, IScheduledJobS Guid ownerUserId = scheduledJobs[0].OwnerUserId; ScheduledJobEntity technicalDataCleanupJob = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), Name = "Technical data cleanup at startup", TaskType = ScheduledTaskType.TechnicalDataCleanup, ScheduleType = ScheduleType.OnceAtStartup, diff --git a/src/Lumina.Infrastructure/Core/Themes/ThemeSynchronizer.cs b/src/Lumina.Infrastructure/Core/Themes/ThemeSynchronizer.cs index 3ce050ad..4c004feb 100644 --- a/src/Lumina.Infrastructure/Core/Themes/ThemeSynchronizer.cs +++ b/src/Lumina.Infrastructure/Core/Themes/ThemeSynchronizer.cs @@ -95,7 +95,7 @@ internal static class ThemeSynchronizer ThemeEntity themeEntity = new() { - Id = Guid.NewGuid(), + Id = Guid.CreateVersion7(), ThemeId = manifestResult.Value.Id, Name = manifestResult.Value.Name, Description = manifestResult.Value.Description, diff --git a/src/Lumina.slnx b/src/Lumina.slnx index 04bf0b64..933a8d49 100644 --- a/src/Lumina.slnx +++ b/src/Lumina.slnx @@ -125,6 +125,7 @@ + diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs index 7170e7ff..6ad763ae 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/UoW/LuminaDbContextTests.cs @@ -1,13 +1,18 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.Authorization; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using Lumina.Application.Common.DataAccess.Entities.Authorization; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary; +using Lumina.DataAccess.Common.ValueGeneration; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -116,6 +121,44 @@ public class LuminaDbContextTests : IDisposable Assert.Contains("Favorites", tableNames); } + [Fact] + public void OnModelCreating_WhenApplied_ShouldUseTimeOrderedGeneratorsForPersistedGuidIdentifiers() + { + // Arrange + List generatedGuidProperties = [.. _context.Model.GetEntityTypes() + .SelectMany(entityType => entityType.GetProperties()) + .Where(property => property.ClrType == typeof(Guid) && property.ValueGenerated == ValueGenerated.OnAdd)]; + + // Act + Assert.All(generatedGuidProperties, property => Assert.NotNull(property.GetValueGeneratorFactory())); + List generatorTypes = [.. generatedGuidProperties.Select(property => property.GetValueGeneratorFactory()!(property, property.DeclaringType).GetType())]; + + // Assert + Assert.Contains(generatedGuidProperties, property => property.DeclaringType.ClrType == typeof(PermissionEntity) && property.Name == nameof(PermissionEntity.Id)); + Assert.Contains(generatedGuidProperties, property => property.DeclaringType.ClrType == typeof(AudioRatingEntity) && property.Name == "Id"); + Assert.All(generatorTypes, generatorType => Assert.Equal(typeof(GuidV7ValueGenerator), generatorType)); + } + + [Fact] + public async Task SaveChangesAsync_WhenAPermissionHasNoId_ShouldAssignAVersion7Identifier() + { + // Arrange + _context.Database.EnsureCreated(); + PermissionEntity permission = new() + { + PermissionName = AuthorizationPermission.CanViewUsers, + CreatedBy = Guid.CreateVersion7(), + CreatedOnUtc = DateTime.UtcNow + }; + _context.Permissions.Add(permission); + + // Act + await _context.SaveChangesAsync(); + + // Assert + Assert.Equal(7, permission.Id.Version); + } + [Fact] public async Task SaveChangesAsync_WhenAddingBook_ShouldPersistItToTheDatabase() {