-
Notifications
You must be signed in to change notification settings - Fork 1
Appt xxx/add point read slide cache site #1633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 17 commits
cc65176
35afcea
f34a991
3115861
608bbd3
e5231d5
3ee288b
1bc23fd
d6ecdb6
3c3d4a6
737eca8
8f733b9
5be0658
5536a72
62f0916
841ca2f
b9e9d80
297d524
05d4107
4a02a3c
4ade28c
fb05571
db34751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ protected override async Task<ApiResult<GetSiteMetaDataResponse>> HandleRequest( | |
| ILogger logger) | ||
| { | ||
| const string scope = "site_details"; | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, scope); | ||
| var site = await siteService.GetSiteByIdAsync(request.Site, false, scope); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function is not used? Can we just delete this? |
||
| if (site != null) | ||
| { | ||
| var patientInformation = site.Accessibilities.Any() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,14 +15,15 @@ public abstract class SiteBasedResourceFunction<TResponse>(IValidator<SiteBasedR | |
| protected override Task<(IReadOnlyCollection<ErrorMessageResponseItem> errors, SiteBasedResourceRequest request)> ReadRequestAsync(HttpRequest req) | ||
| { | ||
| var requestedScope = req.Query.Keys.Contains("scope") ? req.Query["scope"].ToString() : "*"; | ||
| var requestedIgnoreCache = req.Query.Keys.Contains("ignoreCache") && bool.Parse(req.Query["ignoreCache"]); | ||
|
|
||
| if (req.Query.Keys.Contains("site")) | ||
| { | ||
| var site = req.Query["site"]; | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(site, requestedScope))); | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(site, requestedIgnoreCache, requestedScope))); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IgnoreCache should be the last param here |
||
| } | ||
|
|
||
| var siteId = RestUriHelper.GetResourceIdFromPath(req.Path.ToUriComponent(), "sites"); | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(siteId, requestedScope))); | ||
| return Task.FromResult((ErrorMessageResponseItem.None, new SiteBasedResourceRequest(siteId, requestedIgnoreCache, requestedScope))); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| namespace Nhs.Appointments.Api.Models; | ||
|
|
||
| public record SiteBasedResourceRequest(string Site, string Scope); | ||
| public record SiteBasedResourceRequest(string Site, bool IgnoreCache, string Scope); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to last param and maybe default to false? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Nhs.Appointments.Core.Bookings; | ||
|
|
||
| public interface IReferenceNumberDocumentStore | ||
| { | ||
| Task<int> AssignReferenceGroup(); | ||
| Task<int> GetNextSequenceNumber(int prefix); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| using Nhs.Appointments.Core.Caching; | ||
| using Nhs.Appointments.Core.Sites; | ||
|
|
||
| namespace Nhs.Appointments.Core.Bookings; | ||
|
|
@@ -9,37 +10,51 @@ public interface IReferenceNumberProvider | |
|
|
||
| public class ReferenceNumberProvider : IReferenceNumberProvider | ||
| { | ||
| private readonly ISiteStore _siteStore; | ||
| private readonly ISiteService _siteService; | ||
| private readonly ICacheService _cacheService; | ||
| private readonly IReferenceNumberDocumentStore _referenceNumberDocumentStore; | ||
| private readonly TimeProvider _timeProvider; | ||
| public ReferenceNumberProvider( | ||
| ISiteStore siteStore, | ||
| ISiteService siteService, | ||
| ICacheService cacheService, | ||
| IReferenceNumberDocumentStore referenceNumberDocumentStore, | ||
| TimeProvider timeProvider) | ||
| { | ||
| _siteStore = siteStore; | ||
| _siteService = siteService; | ||
| _cacheService = cacheService; | ||
| _referenceNumberDocumentStore = referenceNumberDocumentStore; | ||
| _timeProvider = timeProvider; | ||
| } | ||
| public async Task<string> GetReferenceNumber(string siteId) | ||
| { | ||
| var referenceGroup = await _siteStore.GetReferenceNumberGroup(siteId); | ||
| if (referenceGroup == 0) | ||
| { | ||
| referenceGroup = await _referenceNumberDocumentStore.AssignReferenceGroup(); | ||
| await _siteStore.AssignPrefix(siteId, referenceGroup); | ||
| } | ||
| { | ||
| var referenceNumberGroup = | ||
| await _cacheService.GetCacheValue( | ||
| $"site:referenceNumberGroup:{siteId}", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve cache key from a factory |
||
| new CacheOptions<int>( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We thought about this and decided there's no real benefit to sliding cache here. use the default long lived cache for less complexity |
||
| async () => await GetSitesAssignedReferenceGroup(siteId), | ||
| TimeSpan.FromHours(24))); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configure expiration in app settings |
||
|
|
||
| var sequence = await _referenceNumberDocumentStore.GetNextSequenceNumber(referenceGroup); | ||
| var sequence = await _referenceNumberDocumentStore.GetNextSequenceNumber(referenceNumberGroup); | ||
| var now = _timeProvider.GetUtcNow(); | ||
| var rng = now.Day + now.Second; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another level of randomness here (90-99 are not being used currently) |
||
|
|
||
| return $"{referenceGroup:00}-{rng:00}-{sequence:000000}"; | ||
| return $"{referenceNumberGroup:00}-{rng:00}-{sequence:000000}"; | ||
| } | ||
| } | ||
|
|
||
| private async Task<int> GetSitesAssignedReferenceGroup(string siteId) | ||
| { | ||
| var site = await _siteService.GetSiteByIdAsync(siteId, true); | ||
| if (!SiteHasNotBeenAssignedReferenceGroup(site)) | ||
| { | ||
| return site.ReferenceNumberGroup; | ||
| } | ||
|
|
||
| public interface IReferenceNumberDocumentStore | ||
| { | ||
| Task<int> AssignReferenceGroup(); | ||
| Task<int> GetNextSequenceNumber(int prefix); | ||
| var referenceGroup = await _referenceNumberDocumentStore.AssignReferenceGroup(); | ||
| await _siteService.AssignPrefix(siteId, referenceGroup); | ||
|
|
||
| return referenceGroup; | ||
|
|
||
| } | ||
|
|
||
| private static bool SiteHasNotBeenAssignedReferenceGroup(Site site) => site.ReferenceNumberGroup == 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IgnoreCache should be last param for this method