From 56ae5f459f55dff075d6ae676547ce9a5a6f7603 Mon Sep 17 00:00:00 2001 From: antao Date: Sat, 2 Mar 2019 12:25:08 +0800 Subject: [PATCH] Do some optimization --- lib/inc/drogon/HttpAppFramework.h | 3 --- lib/src/ConfigLoader.cc | 2 -- lib/src/HttpAppFrameworkImpl.cc | 13 +++---------- lib/src/HttpAppFrameworkImpl.h | 4 ---- lib/src/HttpClientImpl.h | 2 +- lib/src/HttpRequestParser.h | 17 ++++++----------- lib/src/HttpServer.cc | 6 +++--- orm_lib/src/DbClientImpl.h | 4 ++-- orm_lib/src/DbClientLockFree.h | 2 +- orm_lib/src/mysql_impl/MysqlResultImpl.h | 2 +- .../src/postgresql_impl/PostgreSQLResultImpl.h | 2 +- orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h | 4 ++-- 12 files changed, 20 insertions(+), 41 deletions(-) diff --git a/lib/inc/drogon/HttpAppFramework.h b/lib/inc/drogon/HttpAppFramework.h index 7aa5cf6e..bdd55bac 100755 --- a/lib/inc/drogon/HttpAppFramework.h +++ b/lib/inc/drogon/HttpAppFramework.h @@ -17,7 +17,6 @@ #include #if USE_ORM #include -#define USE_FAST_CLIENT 1 #endif #include #include @@ -187,10 +186,8 @@ class HttpAppFramework : public trantor::NonCopyable virtual void setServerHeaderField(const std::string &server) = 0; #if USE_ORM virtual orm::DbClientPtr getDbClient(const std::string &name = "default") = 0; -#if USE_FAST_CLIENT virtual void enableFastDbClient() = 0; virtual orm::DbClientPtr getFastDbClient(const std::string &name = "default") = 0; -#endif virtual void createDbClient(const std::string &dbType, const std::string &host, const u_short port, diff --git a/lib/src/ConfigLoader.cc b/lib/src/ConfigLoader.cc index 4af798a2..8cbdfe27 100644 --- a/lib/src/ConfigLoader.cc +++ b/lib/src/ConfigLoader.cc @@ -229,12 +229,10 @@ static void loadApp(const Json::Value &app) auto kickOffTimeout = app.get("idle_connection_timeout", 60).asUInt64(); drogon::app().setIdleConnectionTimeout(kickOffTimeout); #if USE_ORM -#if USE_FAST_CLIENT //Fast db client auto fastDbClient = app.get("enable_fast_db_client", false).asBool(); if (fastDbClient) drogon::app().enableFastDbClient(); -#endif #endif auto server = app.get("server_header_field", "").asString(); if(!server.empty()) diff --git a/lib/src/HttpAppFrameworkImpl.cc b/lib/src/HttpAppFrameworkImpl.cc index 1db02b24..97a8e308 100755 --- a/lib/src/HttpAppFrameworkImpl.cc +++ b/lib/src/HttpAppFrameworkImpl.cc @@ -16,10 +16,8 @@ #include "ConfigLoader.h" #include "HttpServer.h" #if USE_ORM -#if USE_FAST_CLIENT #include "../../orm_lib/src/DbClientLockFree.h" #endif -#endif #include #include #include @@ -68,8 +66,9 @@ static void godaemon(void) close(1); close(2); - open("/dev/null", O_RDWR); - int ret = dup(0); + int ret = open("/dev/null", O_RDWR); + (void)ret; + ret = dup(0); (void)ret; ret = dup(0); (void)ret; @@ -373,11 +372,9 @@ void HttpAppFrameworkImpl::run() #endif #if USE_ORM -#if USE_FAST_CLIENT // Create fast db clients for every io loop if (_enableFastDbClient) createFastDbClient(ioLoops); -#endif #endif _httpCtrlsRouter.init(ioLoops); _httpSimpleCtrlsRouter.init(ioLoops); @@ -414,7 +411,6 @@ void HttpAppFrameworkImpl::run() loop()->loop(); } #if USE_ORM -#if USE_FAST_CLIENT void HttpAppFrameworkImpl::createFastDbClient(const std::vector &ioloops) { for (auto &iter : _dbClientsMap) @@ -433,7 +429,6 @@ void HttpAppFrameworkImpl::createFastDbClient(const std::vector(wsConnPtr); @@ -813,12 +808,10 @@ orm::DbClientPtr HttpAppFrameworkImpl::getDbClient(const std::string &name) { return _dbClientsMap[name]; } -#if USE_FAST_CLIENT orm::DbClientPtr HttpAppFrameworkImpl::getFastDbClient(const std::string &name) { return _dbFastClientsMap[name][trantor::EventLoop::getEventLoopOfCurrentThread()]; } -#endif void HttpAppFrameworkImpl::createDbClient(const std::string &dbType, const std::string &host, const u_short port, diff --git a/lib/src/HttpAppFrameworkImpl.h b/lib/src/HttpAppFrameworkImpl.h index 6beeb579..5101c880 100644 --- a/lib/src/HttpAppFrameworkImpl.h +++ b/lib/src/HttpAppFrameworkImpl.h @@ -119,13 +119,11 @@ class HttpAppFrameworkImpl : public HttpAppFramework #if USE_ORM virtual orm::DbClientPtr getDbClient(const std::string &name = "default") override; -#if USE_FAST_CLIENT virtual void enableFastDbClient() override { _enableFastDbClient = true; } virtual orm::DbClientPtr getFastDbClient(const std::string &name = "default") override; -#endif virtual void createDbClient(const std::string &dbType, const std::string &host, const u_short port, @@ -214,11 +212,9 @@ class HttpAppFrameworkImpl : public HttpAppFramework #if USE_ORM std::map _dbClientsMap; std::vector> _dbFuncs; -#if USE_FAST_CLIENT std::map> _dbFastClientsMap; void createFastDbClient(const std::vector &ioloops); #endif -#endif }; } // namespace drogon diff --git a/lib/src/HttpClientImpl.h b/lib/src/HttpClientImpl.h index 4ba4f981..fab55b9a 100644 --- a/lib/src/HttpClientImpl.h +++ b/lib/src/HttpClientImpl.h @@ -36,7 +36,7 @@ class HttpClientImpl : public HttpClient, public std::enable_shared_from_this> _reqAndCallbacks; void onRecvMessage(const trantor::TcpConnectionPtr &, trantor::MsgBuffer *); diff --git a/lib/src/HttpRequestParser.h b/lib/src/HttpRequestParser.h index bcf2a63b..098cfdd9 100755 --- a/lib/src/HttpRequestParser.h +++ b/lib/src/HttpRequestParser.h @@ -52,17 +52,12 @@ class HttpRequestParser _request.reset(new HttpRequestImpl(_loop)); } - const HttpRequestPtr request() const - { - return _request; - } + // const HttpRequestPtr &request() const + // { + // return _request; + // } - HttpRequestImplPtr request() - { - return _request; - } - - HttpRequestImplPtr requestImpl() + const HttpRequestImplPtr &requestImpl() const { return _request; } @@ -76,7 +71,7 @@ class HttpRequestParser } return false; } - WebSocketConnectionPtr webSocketConn() + const WebSocketConnectionPtr &webSocketConn() const { return _websockConnPtr; } diff --git a/lib/src/HttpServer.cc b/lib/src/HttpServer.cc index 45ccca3e..095aebdc 100755 --- a/lib/src/HttpServer.cc +++ b/lib/src/HttpServer.cc @@ -123,10 +123,10 @@ void HttpServer::onMessage(const TcpConnectionPtr &conn, requestParser->requestImpl()->setPeerAddr(conn->peerAddr()); requestParser->requestImpl()->setLocalAddr(conn->localAddr()); requestParser->requestImpl()->setReceiveDate(trantor::Date::date()); - if (requestParser->firstReq() && isWebSocket(conn, requestParser->request())) + if (requestParser->firstReq() && isWebSocket(conn, requestParser->requestImpl())) { auto wsConn = std::make_shared(conn); - _newWebsocketCallback(requestParser->request(), + _newWebsocketCallback(requestParser->requestImpl(), [=](const HttpResponsePtr &resp) mutable { if (resp->statusCode() == k101SwitchingProtocols) { @@ -138,7 +138,7 @@ void HttpServer::onMessage(const TcpConnectionPtr &conn, wsConn); } else - onRequest(conn, requestParser->request()); + onRequest(conn, requestParser->requestImpl()); requestParser->reset(); } } diff --git a/orm_lib/src/DbClientImpl.h b/orm_lib/src/DbClientImpl.h index 6b14da40..57f75f27 100644 --- a/orm_lib/src/DbClientImpl.h +++ b/orm_lib/src/DbClientImpl.h @@ -84,7 +84,7 @@ class DbClientImpl : public DbClient, public std::enable_shared_from_this &¶meters, std::vector &&length, - std::vector format, + std::vector &&format, QueryCallback &&cb, ExceptPtrCallback &&exceptCb) : _sql(std::move(sql)), @@ -100,7 +100,7 @@ class DbClientImpl : public DbClient, public std::enable_shared_from_this> _sqlCmdBuffer; std::mutex _bufferMutex; - void handleNewTask(const DbConnectionPtr &conn); + void handleNewTask(const DbConnectionPtr &connPtr); }; } // namespace orm diff --git a/orm_lib/src/DbClientLockFree.h b/orm_lib/src/DbClientLockFree.h index 40734447..26b694cd 100644 --- a/orm_lib/src/DbClientLockFree.h +++ b/orm_lib/src/DbClientLockFree.h @@ -66,7 +66,7 @@ class DbClientLockFree : public DbClient, public std::enable_shared_from_this &¶meters, std::vector &&length, - std::vector format, + std::vector &&format, QueryCallback &&cb, ExceptPtrCallback &&exceptCb) : _sql(std::move(sql)), diff --git a/orm_lib/src/mysql_impl/MysqlResultImpl.h b/orm_lib/src/mysql_impl/MysqlResultImpl.h index 7f031e3f..0e12bcbc 100644 --- a/orm_lib/src/mysql_impl/MysqlResultImpl.h +++ b/orm_lib/src/mysql_impl/MysqlResultImpl.h @@ -68,7 +68,7 @@ class MysqlResultImpl : public ResultImpl } virtual size_type size() const noexcept override; virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type Number) const override; + virtual const char *columnName(row_size_type number) const override; virtual size_type affectedRows() const noexcept override; virtual row_size_type columnNumber(const char colName[]) const override; virtual const char *getValue(size_type row, row_size_type column) const override; diff --git a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h index dcd4795e..cce4c3d1 100644 --- a/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h +++ b/orm_lib/src/postgresql_impl/PostgreSQLResultImpl.h @@ -35,7 +35,7 @@ class PostgreSQLResultImpl : public ResultImpl } virtual size_type size() const noexcept override; virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type Number) const override; + virtual const char *columnName(row_size_type number) const override; virtual size_type affectedRows() const noexcept override; virtual row_size_type columnNumber(const char colName[]) const override; virtual const char *getValue(size_type row, row_size_type column) const override; diff --git a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h index 715cb3f1..fb4ffe1c 100644 --- a/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h +++ b/orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.h @@ -29,13 +29,13 @@ namespace orm class Sqlite3ResultImpl : public ResultImpl { public: - Sqlite3ResultImpl(const std::string &query) noexcept + explicit Sqlite3ResultImpl(const std::string &query) noexcept : ResultImpl(query) { } virtual size_type size() const noexcept override; virtual row_size_type columns() const noexcept override; - virtual const char *columnName(row_size_type Number) const override; + virtual const char *columnName(row_size_type number) const override; virtual size_type affectedRows() const noexcept override; virtual row_size_type columnNumber(const char colName[]) const override; virtual const char *getValue(size_type row, row_size_type column) const override;