Skip to content

Commit b9323be

Browse files
committed
fix:compatible with non-standard query parameter
1 parent 3c56289 commit b9323be

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

frameworks/Java/loveqq/src/main/java/com/kfyty/benchmark/example/controller/WebMvcController.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,17 @@ public World db() {
5757
* GET /queries?queries=10 HTTP/1.1
5858
*/
5959
@GetMapping("/queries")
60-
public World[] queries(@RequestParam(defaultValue = "1") Integer queries) {
61-
return Utils.randomWorldNumbers().mapToObj(dbRepository::getWorld).limit(queries).toArray(World[]::new);
60+
public World[] queries(@RequestParam(defaultValue = "1") String queries) {
61+
return Utils.randomWorldNumbers().limit(parseQueryCount(queries)).mapToObj(dbRepository::getWorld).toArray(World[]::new);
6262
}
6363

6464
/**
6565
* GET /updates?queries=10 HTTP/1.1
6666
*/
6767
@GetMapping("/updates")
68-
public List<World> updates(@RequestParam(defaultValue = "1") Integer queries) {
68+
public List<World> updates(@RequestParam(defaultValue = "1") String queries) {
6969
List<World> worlds = Utils.randomWorldNumbers()
70+
.limit(parseQueryCount(queries))
7071
.mapToObj(id -> {
7172
World world = dbRepository.getWorld(id);
7273
int randomNumber;
@@ -76,7 +77,6 @@ public List<World> updates(@RequestParam(defaultValue = "1") Integer queries) {
7677
world.randomNumber = randomNumber;
7778
return world;
7879
})
79-
.limit(queries)
8080
.sorted(Comparator.comparingInt(w -> w.id))
8181
.toList();
8282
dbRepository.updateWorlds(worlds);
@@ -95,4 +95,17 @@ public String fortunes() {
9595

9696
return JStachio.render(new Fortunes(fortunes));
9797
}
98+
99+
private static int parseQueryCount(String textValue) {
100+
if (textValue == null) {
101+
return 1;
102+
}
103+
int parsedValue;
104+
try {
105+
parsedValue = Integer.parseInt(textValue);
106+
} catch (NumberFormatException e) {
107+
return 1;
108+
}
109+
return Math.min(500, Math.max(1, parsedValue));
110+
}
98111
}

frameworks/Java/loveqq/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
k:
22
server:
3-
virtualThread: true
3+
virtualThread: false
44
datasource:
55
type: com.zaxxer.hikari.HikariDataSource
66
driverClassName: org.postgresql.Driver

0 commit comments

Comments
 (0)