@@ -25,6 +25,7 @@ class LicensingDataStore(
2525 const string BrokerMetadataDocumentId = "BrokerMetadata" ;
2626 const string ReportMasksDocumentId = "ReportMasks" ;
2727 const string LicencedEndpointDetailsDocumentId = "LicensedEndpointDetails" ;
28+ const string LicencedEndpointDetailsAmendmentDocumentId = "LicensedEndpointDetailsAmendment" ;
2829
2930 static readonly AuditServiceMetadata DefaultAuditServiceMetadata = new ( [ ] , [ ] ) ;
3031 static readonly ReportConfigurationDocument DefaultReportConfiguration = new ( ) ;
@@ -161,7 +162,8 @@ public async Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointT
161162 {
162163 var endpointDailyThroughputs = timeSeries
163164 . Where ( entry => ! throughputMaxDate . HasValue || entry . Timestamp < maxDateTime )
164- . Select ( entry => new EndpointDailyThroughput ( DateOnly . FromDateTime ( entry . Timestamp ) , ( long ) entry . Value ) ) ;
165+ . Select ( entry => new EndpointDailyThroughput ( DateOnly . FromDateTime ( entry . Timestamp ) , ( long ) entry . Value ) )
166+ . ToList ( ) ;
165167 var throughputData = new ThroughputData ( endpointDailyThroughputs )
166168 {
167169 ThroughputSource = document . EndpointId . ThroughputSource
@@ -341,7 +343,13 @@ public async Task SaveReportMasks(List<string> reportMasks, CancellationToken ca
341343 var store = await storeProvider . GetDocumentStore ( cancellationToken ) ;
342344 using IAsyncDocumentSession session = store . OpenAsyncSession ( databaseConfiguration . Name ) ;
343345
344- return await session . LoadAsync < LicensedEndpointDetails > ( LicencedEndpointDetailsDocumentId , cancellationToken ) ;
346+ var baseDetails = await session . LoadAsync < LicensedEndpointDetails > ( LicencedEndpointDetailsDocumentId , cancellationToken ) ;
347+ if ( baseDetails is null )
348+ {
349+ return null ;
350+ }
351+ var amendments = await session . LoadAsync < LicensedEndpointDetailsAmendment > ( LicencedEndpointDetailsAmendmentDocumentId , cancellationToken ) ;
352+ return baseDetails . Amend ( amendments ) ;
345353 }
346354
347355 public async Task SaveLicensedEndpointDetails ( LicensedEndpointDetails result , CancellationToken cancellationToken = default )
@@ -350,6 +358,24 @@ public async Task SaveLicensedEndpointDetails(LicensedEndpointDetails result, Ca
350358 using IAsyncDocumentSession session = store . OpenAsyncSession ( databaseConfiguration . Name ) ;
351359
352360 await session . StoreAsync ( result , LicencedEndpointDetailsDocumentId , cancellationToken ) ;
361+ await session . StoreAsync ( new LicensedEndpointDetailsAmendment ( ) , LicencedEndpointDetailsAmendmentDocumentId , cancellationToken ) ;
362+ await session . SaveChangesAsync ( cancellationToken ) ;
363+ }
364+
365+ public async Task SaveLicensedEndpointDetailsAmendment ( LicensedEndpointDetailsAmendment result , CancellationToken cancellationToken = default )
366+ {
367+ var store = await storeProvider . GetDocumentStore ( cancellationToken ) ;
368+ using IAsyncDocumentSession session = store . OpenAsyncSession ( databaseConfiguration . Name ) ;
369+
370+ var existing = await session . LoadAsync < LicensedEndpointDetailsAmendment > ( LicencedEndpointDetailsAmendmentDocumentId , cancellationToken ) ;
371+ if ( existing is not null )
372+ {
373+ // these do not round-trip
374+ result . UnmappedQueues = [ .. existing . UnmappedQueues , .. result . UnmappedQueues ] ;
375+ session . Advanced . Evict ( existing ) ;
376+ }
377+
378+ await session . StoreAsync ( result , LicencedEndpointDetailsAmendmentDocumentId , cancellationToken ) ;
353379 await session . SaveChangesAsync ( cancellationToken ) ;
354380 }
355381}
0 commit comments