From 60f7bb6a41cefa95ea775ee8346f3e7772ab4b85 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 7 Apr 2021 12:25:29 +0300 Subject: [PATCH 01/10] DataBaseManagement: remove dead code --- YACReaderLibrary/db/data_base_management.cpp | 15 --------------- YACReaderLibrary/db/data_base_management.h | 6 +----- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index 3e41d77df..dcd714bb5 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -44,21 +44,6 @@ static QString fields = "title ," "hash"; -DataBaseManagement::DataBaseManagement() - : QObject(), dataBasesList() -{ -} - -/*TreeModel * DataBaseManagement::newTreeModel(QString path) -{ - //la consulta se ejecuta... - QSqlQuery selectQuery(loadDatabase(path)); - selectQuery.setForwardOnly(true); - selectQuery.exec("select * from folder order by parentId,name"); - //selectQuery.finish(); - return new TreeModel(selectQuery); -}*/ - QSqlDatabase DataBaseManagement::createDatabase(QString name, QString path) { return createDatabase(QDir::cleanPath(path) + "/" + name + ".ydb"); diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index 3eac4a404..2375861a7 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -29,11 +29,9 @@ class ComicsInfoImporter : public QThread void run() override; }; -class DataBaseManagement : public QObject +class DataBaseManagement { - Q_OBJECT private: - QList dataBasesList; static void bindString(const QString &name, const QSqlRecord &record, QSqlQuery &query); static void bindInt(const QString &name, const QSqlRecord &record, QSqlQuery &query); static void bindDouble(const QString &name, const QSqlRecord &record, QSqlQuery &query); @@ -43,8 +41,6 @@ class DataBaseManagement : public QObject static bool addConstraint(const QString &tableName, const QString &constraint, const QSqlDatabase &db); public: - DataBaseManagement(); - //TreeModel * newTreeModel(QString path); //crea una base de datos y todas sus tablas static QSqlDatabase createDatabase(QString name, QString path); static QSqlDatabase createDatabase(QString dest); From b992d709e9264ebb11380e6c0d03c5116aa336ce Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 7 Apr 2021 12:28:55 +0300 Subject: [PATCH 02/10] Remove some unused and add needed DB-related includes Including only what is used should reduce compilation time. The added includes were necessary to make the respective translation units compile after a thorough cleanup of data_base_management.h includes. This is how the complete include and forward-declaration sections should look like in data_base_management.h: '#'include // (prevent '#' from starting a git comment line) class QSqlDatabase; class QSqlQuery; class QSqlRecord; class QString; class QStringList; Subsequently I had to partly restore the unnecessary includes by moving them from data_base_management.cpp into the header due to the huge number of compilation errors I am not prepared to deal with right now. --- YACReaderLibrary/db/comic_model.h | 1 - YACReaderLibrary/db/comic_query_result_processor.cpp | 4 ++++ YACReaderLibrary/db/data_base_management.cpp | 5 ++++- YACReaderLibrary/db/data_base_management.h | 10 ++++++---- YACReaderLibrary/db/folder_model.h | 1 - YACReaderLibrary/db/folder_query_result_processor.cpp | 4 +++- YACReaderLibrary/db_helper.cpp | 1 + YACReaderLibrary/library_creator.cpp | 2 ++ YACReaderLibrary/library_creator.h | 1 - YACReaderLibrary/library_window.cpp | 1 + YACReaderLibraryServer/libraries_updater.cpp | 1 + 11 files changed, 22 insertions(+), 9 deletions(-) diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index 4d9c05948..1203c02b5 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "yacreader_global_gui.h" diff --git a/YACReaderLibrary/db/comic_query_result_processor.cpp b/YACReaderLibrary/db/comic_query_result_processor.cpp index d00ddebbe..d76c75a98 100644 --- a/YACReaderLibrary/db/comic_query_result_processor.cpp +++ b/YACReaderLibrary/db/comic_query_result_processor.cpp @@ -9,6 +9,10 @@ #include "QsLog.h" +#include +#include +#include + QString getLastExecutedQuery(const QSqlQuery &query) { QString str = query.lastQuery(); diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index dcd714bb5..31c541056 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -1,12 +1,15 @@ #include "data_base_management.h" -#include #include "library_creator.h" #include "check_new_version.h" #include "db_helper.h" #include "QsLog.h" +#include +#include +#include + static QString fields = "title ," "coverPage," diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index 2375861a7..08371c873 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -1,11 +1,13 @@ #ifndef __DATA_BASE_MANAGEMENT_H #define __DATA_BASE_MANAGEMENT_H -#include -#include #include - -#include "folder_model.h" +#include +#include +#include +#include +#include +#include class ComicsInfoExporter : public QThread { diff --git a/YACReaderLibrary/db/folder_model.h b/YACReaderLibrary/db/folder_model.h index 8eb19af17..fdd1cc2ae 100644 --- a/YACReaderLibrary/db/folder_model.h +++ b/YACReaderLibrary/db/folder_model.h @@ -6,7 +6,6 @@ #include #include #include -#include #include "yacreader_global.h" #include "folder_query_result_processor.h" diff --git a/YACReaderLibrary/db/folder_query_result_processor.cpp b/YACReaderLibrary/db/folder_query_result_processor.cpp index 3cbde4547..fd7f41a09 100644 --- a/YACReaderLibrary/db/folder_query_result_processor.cpp +++ b/YACReaderLibrary/db/folder_query_result_processor.cpp @@ -9,8 +9,10 @@ #include "QsLog.h" -#include #include +#include +#include +#include //Copy/pasted from "folder_model.cpp" #define ROOT 1 diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 3a0107560..b9f94662d 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index fc4265134..b6d2c1377 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include "data_base_management.h" #include "qnaturalsorting.h" #include "db_helper.h" +#include "folder_model.h" #include "compressed_archive.h" #include "comic.h" diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h index ccb27f244..3cc6a1f9f 100644 --- a/YACReaderLibrary/library_creator.h +++ b/YACReaderLibrary/library_creator.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include "folder.h" diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 1f68a6d68..ecc8fe9d0 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1,6 +1,7 @@ #include "library_window.h" #include "custom_widgets.h" #include "folder_item.h" +#include "folder_model.h" #include #include diff --git a/YACReaderLibraryServer/libraries_updater.cpp b/YACReaderLibraryServer/libraries_updater.cpp index 104341fcf..906197936 100644 --- a/YACReaderLibraryServer/libraries_updater.cpp +++ b/YACReaderLibraryServer/libraries_updater.cpp @@ -1,5 +1,6 @@ #include "libraries_updater.h" +#include "yacreader_global.h" #include "yacreader_libraries.h" #include "data_base_management.h" From 80b533f1318114b967adec0032822e4186b16d5d Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 7 Apr 2021 12:51:21 +0300 Subject: [PATCH 03/10] DataBaseManagement: take QString by const reference, not by value Even an implicitly shared class is cheaper to pass by reference than by value, as evidenced by Qt APIs themselves. --- YACReaderLibrary/db/data_base_management.cpp | 12 ++++++------ YACReaderLibrary/db/data_base_management.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index 31c541056..76553c888 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -47,12 +47,12 @@ static QString fields = "title ," "hash"; -QSqlDatabase DataBaseManagement::createDatabase(QString name, QString path) +QSqlDatabase DataBaseManagement::createDatabase(const QString &name, const QString &path) { return createDatabase(QDir::cleanPath(path) + "/" + name + ".ydb"); } -QSqlDatabase DataBaseManagement::createDatabase(QString dest) +QSqlDatabase DataBaseManagement::createDatabase(const QString &dest) { QString threadId = QString::number((long long)QThread::currentThreadId(), 16); QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", dest + threadId); @@ -78,7 +78,7 @@ QSqlDatabase DataBaseManagement::createDatabase(QString dest) return db; } -QSqlDatabase DataBaseManagement::loadDatabase(QString path) +QSqlDatabase DataBaseManagement::loadDatabase(const QString &path) { //TODO check path QString threadId = QString::number((long long)QThread::currentThreadId(), 16); @@ -92,7 +92,7 @@ QSqlDatabase DataBaseManagement::loadDatabase(QString path) return db; } -QSqlDatabase DataBaseManagement::loadDatabaseFromFile(QString filePath) +QSqlDatabase DataBaseManagement::loadDatabaseFromFile(const QString &filePath) { //TODO check path QString threadId = QString::number((long long)QThread::currentThreadId(), 16); @@ -307,7 +307,7 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database) return success; } -void DataBaseManagement::exportComicsInfo(QString source, QString dest) +void DataBaseManagement::exportComicsInfo(const QString &source, const QString &dest) { QString connectionName = ""; { @@ -339,7 +339,7 @@ void DataBaseManagement::exportComicsInfo(QString source, QString dest) QSqlDatabase::removeDatabase(connectionName); } -bool DataBaseManagement::importComicsInfo(QString source, QString dest) +bool DataBaseManagement::importComicsInfo(const QString &source, const QString &dest) { QString error; QString driver; diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index 08371c873..b4c29241f 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -44,16 +44,16 @@ class DataBaseManagement public: //crea una base de datos y todas sus tablas - static QSqlDatabase createDatabase(QString name, QString path); - static QSqlDatabase createDatabase(QString dest); + static QSqlDatabase createDatabase(const QString &name, const QString &path); + static QSqlDatabase createDatabase(const QString &dest); //carga una base de datos desde la ruta path - static QSqlDatabase loadDatabase(QString path); - static QSqlDatabase loadDatabaseFromFile(QString path); + static QSqlDatabase loadDatabase(const QString &path); + static QSqlDatabase loadDatabaseFromFile(const QString &path); static bool createTables(QSqlDatabase &database); static bool createV8Tables(QSqlDatabase &database); - static void exportComicsInfo(QString source, QString dest); - static bool importComicsInfo(QString source, QString dest); + static void exportComicsInfo(const QString &source, const QString &dest); + static bool importComicsInfo(const QString &source, const QString &dest); static QString checkValidDB(const QString &fullPath); //retorna "" si la DB es inválida ó la versión si es válida. static int compareVersions(const QString &v1, const QString v2); //retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2 From cffe11759f96e442f744ae4ffc81ccb3d89c4d25 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 7 Apr 2021 15:23:40 +0300 Subject: [PATCH 04/10] DBHelper::updateFolderTreeManga: reorder arguments for consistency All other similar updating functions take db as the last argument. --- YACReaderLibrary/db/folder_model.cpp | 2 +- YACReaderLibrary/db_helper.cpp | 4 ++-- YACReaderLibrary/db_helper.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/YACReaderLibrary/db/folder_model.cpp b/YACReaderLibrary/db/folder_model.cpp index 35271125a..5a9616fb9 100644 --- a/YACReaderLibrary/db/folder_model.cpp +++ b/YACReaderLibrary/db/folder_model.cpp @@ -385,7 +385,7 @@ void FolderModel::updateFolderManga(const QModelIndexList &list, bool manga) setManga(item, manga); - DBHelper::updateFolderTreeManga(item->id, db, manga); + DBHelper::updateFolderTreeManga(item->id, manga, db); } db.commit(); connectionName = db.connectionName(); diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index b9f94662d..aac451916 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -1520,7 +1520,7 @@ QList