mirror of
https://github.com/floci-io/floci.git
synced 2026-11-25 06:47:41 -05:00
fix(transcribe): honor list pagination tokens (#3927)
* fix(transcribe): advance list pagination tokens * fix(transcribe): keep pagination stable across mutations
This commit is contained in:
1 parent
9c4cd8c9e1
commit
1088187cb3
5 files changed
+160
-16
No files matched your search
+4
-2
@@ -50,9 +50,10 @@ public class TranscribeJsonHandler {
|
||||
yield Response.ok(Map.of("TranscriptionJob", job)).build();
|
||||
}
|
||||
case "ListTranscriptionJobs" -> {
|
||||
var result = transcribeService.listTranscriptionJobs(
|
||||
TranscribeService.ListTranscriptionJobsResult result = transcribeService.listTranscriptionJobs(
|
||||
getStringField(request, "Status"),
|
||||
getStringField(request, "JobNameContains"),
|
||||
getStringField(request, "NextToken"),
|
||||
getIntField(request, "MaxResults"));
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
if (result.status() != null) {
|
||||
@@ -82,9 +83,10 @@ public class TranscribeJsonHandler {
|
||||
yield Response.ok(vocab).build();
|
||||
}
|
||||
case "ListVocabularies" -> {
|
||||
var result = transcribeService.listVocabularies(
|
||||
TranscribeService.ListVocabulariesResult result = transcribeService.listVocabularies(
|
||||
getStringField(request, "StateEquals"),
|
||||
getStringField(request, "NameContains"),
|
||||
getStringField(request, "NextToken"),
|
||||
getIntField(request, "MaxResults"));
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
if (result.status() != null) {
|
||||
|
||||
+36
-8
@@ -99,7 +99,7 @@ public class TranscribeService implements Resettable {
|
||||
}
|
||||
|
||||
public ListTranscriptionJobsResult listTranscriptionJobs(String statusFilter, String jobNameContains,
|
||||
Integer maxResults) {
|
||||
String nextToken, Integer maxResults) {
|
||||
int limit = maxResults != null ? Math.min(maxResults, 100) : 100;
|
||||
|
||||
String currentPrefix = currentJobPrefix();
|
||||
@@ -112,11 +112,13 @@ public class TranscribeService implements Resettable {
|
||||
.map(TranscriptionJobSummary::from)
|
||||
.toList();
|
||||
|
||||
List<TranscriptionJobSummary> page = filtered.subList(0, Math.min(limit, filtered.size()));
|
||||
String nextToken = page.size() < filtered.size()
|
||||
int startIndex = transcriptionJobStartIndex(filtered, nextToken);
|
||||
int endIndex = Math.min(startIndex + limit, filtered.size());
|
||||
List<TranscriptionJobSummary> page = filtered.subList(startIndex, endIndex);
|
||||
String resultNextToken = endIndex < filtered.size()
|
||||
? page.get(page.size() - 1).transcriptionJobName() : null;
|
||||
|
||||
return new ListTranscriptionJobsResult(page, statusFilter, nextToken);
|
||||
return new ListTranscriptionJobsResult(page, statusFilter, resultNextToken);
|
||||
}
|
||||
|
||||
public void deleteTranscriptionJob(String jobName) {
|
||||
@@ -153,7 +155,7 @@ public class TranscribeService implements Resettable {
|
||||
}
|
||||
|
||||
public ListVocabulariesResult listVocabularies(String stateEquals, String nameContains,
|
||||
Integer maxResults) {
|
||||
String nextToken, Integer maxResults) {
|
||||
int limit = maxResults != null ? Math.min(maxResults, 100) : 100;
|
||||
|
||||
migrateDefaultScopeVocabularies();
|
||||
@@ -167,11 +169,13 @@ public class TranscribeService implements Resettable {
|
||||
.sorted(Comparator.comparing(VocabularyInfo::vocabularyName))
|
||||
.toList();
|
||||
|
||||
List<VocabularyInfo> page = filtered.subList(0, Math.min(limit, filtered.size()));
|
||||
String nextToken = page.size() < filtered.size()
|
||||
int startIndex = vocabularyStartIndex(filtered, nextToken);
|
||||
int endIndex = Math.min(startIndex + limit, filtered.size());
|
||||
List<VocabularyInfo> page = filtered.subList(startIndex, endIndex);
|
||||
String resultNextToken = endIndex < filtered.size()
|
||||
? page.get(page.size() - 1).vocabularyName() : null;
|
||||
|
||||
return new ListVocabulariesResult(page, stateEquals, nextToken);
|
||||
return new ListVocabulariesResult(page, stateEquals, resultNextToken);
|
||||
}
|
||||
|
||||
public void deleteVocabulary(String vocabularyName) {
|
||||
@@ -225,6 +229,30 @@ public class TranscribeService implements Resettable {
|
||||
.forEach(this::getStoredVocabulary);
|
||||
}
|
||||
|
||||
private int transcriptionJobStartIndex(List<TranscriptionJobSummary> jobs, String nextToken) {
|
||||
if (nextToken == null) {
|
||||
return 0;
|
||||
}
|
||||
for (int index = 0; index < jobs.size(); index++) {
|
||||
if (jobs.get(index).transcriptionJobName().compareTo(nextToken) > 0) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return jobs.size();
|
||||
}
|
||||
|
||||
private int vocabularyStartIndex(List<VocabularyInfo> vocabularyList, String nextToken) {
|
||||
if (nextToken == null) {
|
||||
return 0;
|
||||
}
|
||||
for (int index = 0; index < vocabularyList.size(); index++) {
|
||||
if (vocabularyList.get(index).vocabularyName().compareTo(nextToken) > 0) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return vocabularyList.size();
|
||||
}
|
||||
|
||||
private void requireNonBlank(String value, String fieldName) {
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
|
||||
Reference in new issue
Block a user