Browse Source

Cutelyst update and fixes (#6249)

* cutelyst: build fixes

* cutelyst: Find PostgreSQL to allow asql static linking

* cutelyst: Fix linking with wsgi

* cutelyst: mimalloc optional

* cutelyst: fix update batch async

* cutelyst: Fix batched error

* cutelyst: update to 2.14
Daniel Nicoletti 4 years ago
parent
commit
603cdca53a

+ 2 - 2
frameworks/C++/cutelyst/build.sh

@@ -1,8 +1,8 @@
 #!/bin/bash
 
-export ASQL_VER=0.19.0
+export ASQL_VER=0.26.0
 export CUTELEE_VER=5.3.0
-export CUTELYST_VER=2.13.0
+export CUTELYST_VER=2.14.0
 
 apt update -qq && \
     apt install -yqq --no-install-recommends \

+ 15 - 2
frameworks/C++/cutelyst/src/CMakeLists.txt

@@ -2,9 +2,14 @@ cmake_minimum_required(VERSION 3.6.0 FATAL_ERROR)
 
 project(cutelyst_benchmarks LANGUAGES CXX)
 
+cmake_policy(SET CMP0069 NEW)
+
 find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core Network Sql)
 find_package(ASqlQt5 0.15.0 REQUIRED)
 find_package(Cutelyst2Qt5 2.12 REQUIRED)
+find_package(Cutelee5 REQUIRED)
+find_package(PostgreSQL REQUIRED)
+find_package(mimalloc 1.0)
 
 # Auto generate moc files
 set(CMAKE_AUTOMOC ON)
@@ -53,10 +58,18 @@ target_link_libraries(cutelyst_benchmarks
     ASqlQt5::Core
 )
 
-add_executable(cutelyst-benchmarks main.cpp)
+add_executable(cutelyst-benchmarks ${cutelyst_benchmarks_SRCS} main.cpp)
 target_link_libraries(cutelyst-benchmarks
+    PUBLIC
     Cutelyst::Core
     Cutelyst::WSGI
+    Cutelyst::Utils::Sql
+    Cutelyst::View::Cutelee
+    Qt5::Core
     Qt5::Network
-    cutelyst_benchmarks
+    Qt5::Sql
+    ASqlQt5::Core
 )
+if (mimalloc_FOUND)
+    target_link_libraries(cutelyst-benchmarks PUBLIC mimalloc)
+endif ()

+ 11 - 5
frameworks/C++/cutelyst/src/databaseupdatestest.cpp

@@ -12,6 +12,8 @@
 #include <QJsonObject>
 #include <QJsonArray>
 
+#include <QLoggingCategory>
+
 DatabaseUpdatesTest::DatabaseUpdatesTest(QObject *parent) : Controller(parent)
 {
 
@@ -41,14 +43,14 @@ void DatabaseUpdatesTest::updatep(Context *c)
 
         db.execPrepared(APreparedQueryLiteral("SELECT randomNumber, id FROM world WHERE id=$1"),
                                {id}, [c, async] (AResult &result) {
-            if (Q_UNLIKELY(result.error() && !result.size())) {
+            if (Q_UNLIKELY(result.error() || !result.size())) {
                 c->res()->setStatus(Response::InternalServerError);
                 return;
             }
         }, c);
         db.execPrepared(APreparedQueryLiteral("UPDATE world SET randomNumber=$1 WHERE id=$2"),
                                {randomNumber, id}, [c, async] (AResult &result) {
-            if (Q_UNLIKELY(result.error() && !result.size())) {
+            if (Q_UNLIKELY(result.error())) {
                 c->res()->setStatus(Response::InternalServerError);
                 return;
             }
@@ -89,7 +91,7 @@ void DatabaseUpdatesTest::updateb(Context *c)
 
         db.execPrepared(APreparedQueryLiteral("SELECT randomNumber, id FROM world WHERE id=$1"),
                                {id}, [c, async] (AResult &result) {
-            if (Q_UNLIKELY(result.error() && !result.size())) {
+            if (Q_UNLIKELY(result.error() || !result.size())) {
                 c->res()->setStatus(Response::InternalServerError);
                 return;
             }
@@ -99,7 +101,7 @@ void DatabaseUpdatesTest::updateb(Context *c)
 
     const APreparedQuery pq = getSql(queries);
     db.execPrepared(pq, args, [c, async] (AResult &result) {
-        if (Q_UNLIKELY(result.error() && !result.size())) {
+        if (Q_UNLIKELY(result.error())) {
             c->res()->setStatus(Response::InternalServerError);
             return;
         }
@@ -189,9 +191,13 @@ APreparedQuery DatabaseUpdatesTest::getSql(int count)
     sql.append(QStringLiteral("ELSE randomnumber END WHERE id IN ("));
 
     for (int i = 0; i < count; i++) {
-        sql.append(QLatin1Char('$') + QString::number(placeholdersCounter));
+        sql.append(QLatin1Char('$') + QString::number(placeholdersCounter) + QLatin1Char(','));
         ++placeholdersCounter;
     }
+
+    if (count) {
+        sql.remove(sql.size() - 1, 1);
+    }
     sql.append(QLatin1Char(')'));
     m_sqlMap.insert(count, sql);