Conversation
| protected override async Task<ApiResult<Site>> HandleRequest(SiteBasedResourceRequest request, ILogger logger) | ||
| { | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, request.Scope); | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, request.IgnoreCache, request.Scope); |
There was a problem hiding this comment.
IgnoreCache should be last param for this method
| { | ||
| const string scope = "site_details"; | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, scope); | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, false, scope); |
There was a problem hiding this comment.
I think this function is not used? Can we just delete this?
| { | ||
| var site = req.Query["site"]; | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(site, requestedScope))); | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(site, requestedIgnoreCache, requestedScope))); |
There was a problem hiding this comment.
IgnoreCache should be the last param here
| namespace Nhs.Appointments.Api.Models; | ||
|
|
||
| public record SiteBasedResourceRequest(string Site, string Scope); | ||
| public record SiteBasedResourceRequest(string Site, bool IgnoreCache, string Scope); |
There was a problem hiding this comment.
Move to last param and maybe default to false?
| $"site:referenceNumberGroup:{siteId}", | ||
| new CacheOptions<int>( | ||
| async () => await GetSitesAssignedReferenceGroup(siteId), | ||
| TimeSpan.FromHours(24))); |
There was a problem hiding this comment.
Configure expiration in app settings
| { | ||
| var referenceNumberGroup = | ||
| await _cacheService.GetCacheValue( | ||
| $"site:referenceNumberGroup:{siteId}", |
There was a problem hiding this comment.
Resolve cache key from a factory
| var sequence = await _referenceNumberDocumentStore.GetNextSequenceNumber(referenceGroup); | ||
| var sequence = await _referenceNumberDocumentStore.GetNextSequenceNumber(referenceNumberGroup); | ||
| var now = _timeProvider.GetUtcNow(); | ||
| var rng = now.Day + now.Second; |
There was a problem hiding this comment.
Another level of randomness here (90-99 are not being used currently)
| var referenceNumberGroup = | ||
| await _cacheService.GetCacheValue( | ||
| $"site:referenceNumberGroup:{siteId}", | ||
| new CacheOptions<int>( |
There was a problem hiding this comment.
We thought about this and decided there's no real benefit to sliding cache here. use the default long lived cache for less complexity
|
|
||
| public interface ISiteService | ||
| { | ||
| Task<Site> GetSiteByIdAsync(string siteId, string scope = "*"); |
There was a problem hiding this comment.
Ignore cache should be the last param and it should be a enum.
enum should be called something like - DataSource
enum values should follow something like - "UseDatabase", "UseCache"
| } | ||
| else | ||
| { | ||
| site = await cacheService.GetLazySlidingCacheValue($"site:{siteId}", |
There was a problem hiding this comment.
cache key factory here
| { | ||
| var site = await siteStore.GetSiteById(siteId); | ||
| Site site; | ||
| if (options.Value.DisableSiteCache || ignoreCache) |
There was a problem hiding this comment.
Invert if and move and introduce a private method for use cache
| /// <summary> | ||
| /// The duration, in minutes, to cache site for. | ||
| /// </summary> | ||
| public int SiteCacheDurationMinutes { get; set; } |
There was a problem hiding this comment.
Add getter to expose these int's as timespan that can then be unit tested
| [CosmosDocumentType("reference_group")] | ||
| public class BookingReferenceGroupDocument : BookingReferenceDataCosmosDocument | ||
| { | ||
| public int SiteCount { get; set; } |
There was a problem hiding this comment.
Debate should prefix be explicit or use Id as this implementation does
There was a problem hiding this comment.
Maybe just expose it here?
|
|
||
| referenceGroupDocuments = (await _cosmosStore.RunQueryAsync<BookingReferenceGroupDocument>(x => x.DocumentType == docType)).ToArray(); | ||
|
|
||
| if (!referenceGroupDocuments.Any()) |
| } | ||
|
|
||
| var target = referenceGroupDocuments.Where(g => g.Id != 0.ToString()).OrderBy(g => g.SiteCount).ThenBy(g => g.Id).First(); | ||
| var siteCountIncrement = PatchOperation.Increment($"/SiteCount", 1); |
There was a problem hiding this comment.
Magic strings to static class
There was a problem hiding this comment.
Object orientated? ReferenceGroupOperation.SiteIncrement() OR ReferenceGroupOperation.UpdateSiteCount()
There was a problem hiding this comment.
Maybe should live on the BookingReferenceGroupDocument
|
|
||
| public async Task<int> GetNextSequenceNumber(int prefix) | ||
| { | ||
| var incrementSequencePatch = PatchOperation.Increment($"/Sequence", 1); |
|
|
||
| export const fetchSite = async ( | ||
| siteId: string, | ||
| ignoreCache: boolean, |
There was a problem hiding this comment.
Use the enum like in the API layor
| isDeleted: dataTable.GetBoolRowValueOrDefault(row, "IsDeleted"), | ||
| Type: dataTable.GetRowValueOrDefault(row, "Type") | ||
| Type: dataTable.GetRowValueOrDefault(row, "Type"), | ||
| ReferenceNumberGroup: 0 |
There was a problem hiding this comment.
Can we do this once somewhere please?
There was a problem hiding this comment.
Maybe use -1 by default
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Checklist: