mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 01:11:10 +00:00
Adds playlist management and playback
This commit is contained in:
1 parent
009a0c8156
commit
9889c86c76
296 files changed
+18830
-367
No files matched your search
+24
-2
@@ -33,7 +33,7 @@ SQLite Write-Ahead Logging (`PRAGMA journal_mode=WAL`) and a busy timeout are en
|
||||
### Risks and Tradeoffs
|
||||
| Risk | Mitigation Strategy |
|
||||
|-------------------------------|-------------------------------------------------------------------|
|
||||
| Raw SQL duplication | All raw SQL is confined to the two bulk repositories, behind the repository and unit of work abstractions |
|
||||
| Raw SQL duplication | All raw SQL is confined to the bulk repositories (the scan jobs and the documented playlist append), behind the repository and unit of work abstractions |
|
||||
| Concurrency errors | WAL and a busy timeout are enabled at startup, and the bulk operations run on dedicated connections |
|
||||
| Layer integrity | Dapper is referenced only by the DataAccess layer |
|
||||
|
||||
@@ -47,4 +47,26 @@ Bulk statements would run on the same connection as the tracked queries of the j
|
||||
### 2. Third party bulk library (for example EF Core bulk extensions)
|
||||
A dedicated bulk extension library would abstract the raw SQL.
|
||||
|
||||
**Rejected**: Dapper is a small, widely adopted and dependency free mapper, and the amount of raw SQL is small and confined to two repositories. See the ADRs of the scan subsystem for the exact statements.
|
||||
**Rejected**: Dapper is a small, widely adopted and dependency free mapper, and the amount of raw SQL is small and confined to the bulk repositories. See the ADRs of the scan subsystem for the exact statements, and the amendment below for the playlist append.
|
||||
|
||||
## Amendment: Playlist Whole-Library Appends (2026-10-20)
|
||||
|
||||
The playlist feature needs to append a whole library, which can contain hundreds of thousands of tracks, to a playlist in one request. The Entity Framework change tracker cannot materialize that graph, so `PlaylistRepository.AddEntriesAsync` performs the append with parameterized multi-row `INSERT` statements in bounded batches.
|
||||
|
||||
Unlike the scan jobs, this bulk operation deliberately uses the connection and the transaction of the request's unit of work, not a dedicated connection. The request middleware already holds the SQLite write transaction, and a dedicated connection would wait on that lock while the request waits on the append. Sharing the request transaction keeps the append atomic with the ownership check and the activity update, and the busy timeout plus the unique `(PlaylistId, Position)` index turn a concurrent append into a mapped conflict instead of a duplicate position.
|
||||
|
||||
The exception is confined to the append and the rare sparse-key rebalance in `PlaylistRepository` and is documented in the class remarks. Moves and removals use Entity Framework `ExecuteUpdateAsync` and `ExecuteDeleteAsync` on their normal path, so they keep the model, the transaction and the error mapping. The rebalance uses raw SQL only when repeated midpoint moves exhaust the numeric gap between two neighbors; it respaces the order keys through a temporary table inside the request transaction.
|
||||
|
||||
## Amendment: Playlist Scope Ordering and Rollback (2026-10-21)
|
||||
|
||||
A whole library, artist or album scope is now appended with one `INSERT ... SELECT` statement in `PlaylistRepository.AddScopeEntriesAsync`. The statement joins the catalogue tables, orders the tracks with `ROW_NUMBER()` in SQLite and computes the sparse positions as part of the insert, so the scope is never materialized, sorted in memory or sent to the data access layer as a list of Ids. Explicit track lists still use the batched `AddEntriesAsync` path, because that list is already in memory.
|
||||
|
||||
An append that fails or is cancelled rolls the request transaction back explicitly. The context records that rollback, and the eventual consistency middleware skips the commit and logs it when the response still reports success, instead of committing a partially written operation.
|
||||
|
||||
## Amendment: Request Transaction Ownership and Aborted Requests (2026-10-21)
|
||||
|
||||
The eventual consistency middleware now begins, commits and rolls back the request transaction through `IUnitOfWork`, so the transaction boundary follows the unit of work instead of the `DbContext` being used directly. The commit-before-publish sequence of ADR-0002 is unchanged.
|
||||
|
||||
An aborted request is no longer left at its default success status: the exception handling middleware reports it as `499 Client Closed Request` and rethrows. The eventual consistency middleware therefore decides from the response status alone. It commits a 2xx response and rolls back every other response, including an abort, and it deliberately does not consult the request abort token, because that token can already be cancelled after a successful operation whose response was already sent.
|
||||
|
||||
This replaces the in-context rollback marker and the repository's rollback of the ambient request transaction described in the previous amendment. A repository now only commits or rolls back a transaction it opened itself, which happens when it runs without an ambient request transaction. A partially written append is therefore discarded by the middleware's rollback, not by a signal from the repository.
|
||||
+14
@@ -82,3 +82,17 @@ Introduce a generic persistence engine driven by a per-aggregate profile describ
|
||||
Stop modeling shared references as a shared table keyed by name, and store them per aggregate, removing the duplicate-key-in-graph class of bug at the source.
|
||||
|
||||
**Rejected**: it requires a database schema change and changes query behavior for shared references, which is out of scope. The shared tables are kept, and the concern is handled where it belongs, in the persistence toolkit.
|
||||
|
||||
## Amendment: Set-Based Playlist Entry Operations (2026-10-20)
|
||||
|
||||
The playlist entries are mutated by set-based storage operations because a playlist can hold a whole library. The batched raw append and the `ExecuteUpdateAsync` and `ExecuteDeleteAsync` move and removal statements bypass the change tracker and therefore also bypass the auditing interceptor.
|
||||
|
||||
Those operations stamp `UpdatedOnUtc` and `UpdatedBy` on the playlist row themselves, stamp the creation or update audit columns of the entry rows they write, and increment the playlist concurrency token, in the same transaction. This is the only exception to the rule that the auditing interceptor is the only writer of the audit columns. Details edits still go through `EditableValuesCopier` and leave the audit columns to the interceptor. The exception is confined to `PlaylistRepository` and is documented in the class remarks.
|
||||
|
||||
Ordering is storage owned as well. The unique index on `(PlaylistId, Position)` is the enforced invariant, and the positions are sparse order keys rather than dense indices. A move normally changes one key to the midpoint between its new neighbors, and a removal deletes one row, so neither rewrites the following range. If repeated midpoint moves exhaust the numeric gap between two neighbors, a rare rebalance respaces the keys with a temporary table and two passes so the unique index is never violated. The domain only rejects duplicate positions on reconstitution, so a storage gap is readable instead of making the playlist impossible to load.
|
||||
|
||||
## Amendment: Playlist Entry Count and Change Detection (2026-10-21)
|
||||
|
||||
The playlist row now carries a denormalized `EntryCount`, maintained by the set-based append and removal operations in the same statement that updates the playlist activity time and concurrency token. Window reads, moves and the single-add read-back use that column instead of counting the entries of the playlist, so none of them scan an index proportional to the playlist size.
|
||||
|
||||
Details edits still go through `EditableValuesCopier`, but the copier now compares the incoming value with the tracked value before assigning it and marks only an actual change as modified. `PlaylistRepository.UpdateAsync` also compares the tracked original values explicitly before it decides to increment the concurrency token, so a no-op save neither restamps the row nor bumps its version.
|
||||
Reference in new issue
Block a user