Browse Source

Update Dancer query to pass the test (#4631)

Joan Miquel 6 years ago
parent
commit
42873e9f8f
2 changed files with 12 additions and 9 deletions
  1. 11 8
      frameworks/Perl/dancer/app.pl
  2. 1 1
      frameworks/Perl/dancer/benchmark_config.json

+ 11 - 8
frameworks/Perl/dancer/app.pl

@@ -16,7 +16,7 @@ get '/json' => sub {
     { message => 'Hello, World!' }
 };
 
-get '/db' => sub {
+get '/dbquery' => sub {
     my $queries = params->{queries} || 1;
     $queries = 1 if ( $queries !~ /^\d+$/ || $queries < 1 );
     $queries = 500 if $queries > 500;
@@ -26,16 +26,19 @@ get '/db' => sub {
         my $id = int rand 10000 + 1;
         $sth->execute($id);
         if ( my $row = $sth->fetchrow_hashref ) {
-            if ( $queries == 1 ) {
-                return { id => $id, randomNumber => $row->{randomNumber} };
-            }
-            else {
-                push @response,
-                  { id => $id, randomNumber => $row->{randomNumber} };
-            }
+            push @response,
+                { id => $id, randomNumber => $row->{randomNumber} };
         }
     }
     return \@response;
 };
 
+get '/db' => sub {
+    my $id = int rand 10000 + 1;
+    $sth->execute($id);
+    if ( my $row = $sth->fetchrow_hashref ) {
+            return { id => $id, randomNumber => $row->{randomNumber} };
+    }
+};
+
 Dancer->dance;

+ 1 - 1
frameworks/Perl/dancer/benchmark_config.json

@@ -4,7 +4,7 @@
     "default": {
       "json_url": "/json",
       "db_url": "/db",
-      "query_url": "/db?queries=",
+      "query_url": "/dbquery?queries=",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",