|
3 | 3 | using AAS.TwinEngine.DataEngine.ApplicationLogic.Extensions; |
4 | 4 | using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.AasRepository; |
5 | 5 | using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Plugin; |
| 6 | +using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Shared; |
6 | 7 | using AAS.TwinEngine.DataEngine.ApplicationLogic.Services.Shared.Providers; |
7 | 8 | using AAS.TwinEngine.DataEngine.DomainModel.AasRegistry; |
8 | 9 | using AAS.TwinEngine.DataEngine.DomainModel.AasRepository; |
@@ -98,7 +99,7 @@ public async Task<SubmodelList> GetAllSubmodelsAsync(SubmodelSearchFilter? filte |
98 | 99 | private async Task<SubmodelPageResult> CollectSubmodelPageAsync(ShellSearchFilter shellSearchFilter, int pageSize, string? encodedCursor, CancellationToken cancellationToken) |
99 | 100 | { |
100 | 101 | var incomingCursor = SubmodelPaginationCursor.Decode(encodedCursor); |
101 | | - var state = new PaginationState(incomingCursor, pageSize); |
| 102 | + var state = new SubmodelPaginationState(incomingCursor, pageSize); |
102 | 103 | var pluginCursor = state.TrackingAasId; |
103 | 104 |
|
104 | 105 | while (state.CollectedIds.Count < pageSize) |
@@ -127,12 +128,10 @@ private async Task<SubmodelPageResult> CollectSubmodelPageAsync(ShellSearchFilte |
127 | 128 | pluginCursor = state.TrackingAasId; |
128 | 129 | } |
129 | 130 |
|
130 | | - var nextCursor = state.CollectedIds.Count >= pageSize ? SubmodelPaginationCursor.Encode(state.LastCollectedSubmodelId, state.TrackingAasId) : null; |
131 | | - |
132 | | - return new SubmodelPageResult(state.CollectedIds, nextCursor); |
| 131 | + return new SubmodelPageResult(state.CollectedIds, state.BuildNextCursor(pageSize)); |
133 | 132 | } |
134 | 133 |
|
135 | | - private async Task<bool> ProcessShellBatchAsync(IReadOnlyList<ShellDescriptorMetaData> shellDescriptors, int pageSize, PaginationState state, CancellationToken cancellationToken) |
| 134 | + private async Task<bool> ProcessShellBatchAsync(IReadOnlyList<ShellDescriptorMetaData> shellDescriptors, int pageSize, SubmodelPaginationState state, CancellationToken cancellationToken) |
136 | 135 | { |
137 | 136 | var prefetchTasks = new Task<List<string>>[shellDescriptors.Count]; |
138 | 137 | using var semaphore = new SemaphoreSlim(_concurrentOperationsLimit, _concurrentOperationsLimit); |
@@ -161,38 +160,10 @@ private async Task<bool> ProcessShellBatchAsync(IReadOnlyList<ShellDescriptorMet |
161 | 160 |
|
162 | 161 | var submodelIds = allSubmodelIds[idx]; |
163 | 162 |
|
164 | | - if (submodelIds.Count == 0) |
| 163 | + if (state.CollectSubmodelIds(submodelIds, shellId, pageSize)) |
165 | 164 | { |
166 | | - state.TrackingAasId = shellId; |
167 | | - state.ResumeAfterSubmodelId = null; |
168 | | - continue; |
| 165 | + return true; |
169 | 166 | } |
170 | | - |
171 | | - var startIndex = 0; |
172 | | - |
173 | | - if (state.ResumeAfterSubmodelId is not null) |
174 | | - { |
175 | | - startIndex = submodelIds.IndexOf(state.ResumeAfterSubmodelId) + 1; |
176 | | - state.ResumeAfterSubmodelId = null; |
177 | | - } |
178 | | - |
179 | | - for (var i = startIndex; i < submodelIds.Count; i++) |
180 | | - { |
181 | | - state.CollectedIds.Add(submodelIds[i]); |
182 | | - state.LastCollectedSubmodelId = submodelIds[i]; |
183 | | - |
184 | | - if (state.CollectedIds.Count >= pageSize) |
185 | | - { |
186 | | - if (submodelIds[^1] == state.LastCollectedSubmodelId) |
187 | | - { |
188 | | - state.TrackingAasId = shellId; |
189 | | - } |
190 | | - |
191 | | - return true; |
192 | | - } |
193 | | - } |
194 | | - |
195 | | - state.TrackingAasId = shellId; |
196 | 167 | } |
197 | 168 |
|
198 | 169 | return false; |
@@ -226,15 +197,6 @@ private async Task<List<string>> GetSubmodelIdsForShellAsync(string shellId, Can |
226 | 197 | } |
227 | 198 | } |
228 | 199 |
|
229 | | - private sealed record SubmodelPageResult(List<string> SubmodelIds, string? NextCursor); |
230 | | - |
231 | | - private sealed class PaginationState(SubmodelPaginationCursor? cursor, int capacity) |
232 | | - { |
233 | | - public List<string> CollectedIds { get; } = new(capacity); |
234 | | - public string? TrackingAasId { get; set; } = cursor?.AasId; |
235 | | - public string? LastCollectedSubmodelId { get; set; } |
236 | | - public string? ResumeAfterSubmodelId { get; set; } = cursor?.SubmodelId; |
237 | | - } |
238 | 200 |
|
239 | 201 | private async Task<List<ISubmodel>> BuildSubmodelsAsync(List<string> submodelIds, string? filteredTemplateId, SubmodelQueryOptions? queryOptions, CancellationToken cancellationToken) |
240 | 202 | { |
|
0 commit comments