From 639452472a7d10ab5bafac4c4ab81cd9ee34e893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Walenciak?= Date: Tue, 28 May 2024 20:59:00 +0200 Subject: [PATCH] Simplify --- src/core/task_executor_utils.hpp | 8 +++----- .../database_tools/implementation/photos_analyzer.cpp | 4 ++-- .../database_tools/implementation/series_detector.cpp | 2 +- src/gui/desktop/quick_items/context_menu_manager.cpp | 2 +- src/gui/desktop/utils/people_editor.cpp | 10 +++++----- src/gui/desktop/utils/thumbnail_manager.cpp | 4 ++-- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/core/task_executor_utils.hpp b/src/core/task_executor_utils.hpp index ad8d0d5b11..63e0a01e2b 100644 --- a/src/core/task_executor_utils.hpp +++ b/src/core/task_executor_utils.hpp @@ -50,16 +50,14 @@ class CORE_EXPORT WorkState // Helper function. // Run a task and wait for it to be finished. -template +template [[nodiscard]] auto evaluate(E& executor, const T& task) { - using PTask = std::packaged_task; - - PTask p_task(task); + std::packaged_task p_task(task); auto result_future = p_task.get_future(); - ExecutorTraits::exec(executor, std::move(p_task)); + ExecutorTraits::exec(executor, std::move(p_task)); result_future.wait(); diff --git a/src/database/database_tools/implementation/photos_analyzer.cpp b/src/database/database_tools/implementation/photos_analyzer.cpp index 3e03a989cf..e3e095f462 100644 --- a/src/database/database_tools/implementation/photos_analyzer.cpp +++ b/src/database/database_tools/implementation/photos_analyzer.cpp @@ -138,9 +138,9 @@ namespace void perform() override { - using namespace Photo; - auto data = evaluate(Database::IBackend &)>(*m_storage, [this](Database::IBackend& backend) + auto data = evaluate(*m_storage, [this](Database::IBackend& backend) { + using namespace Photo; return backend.getPhotoDelta(m_id); }); diff --git a/src/database/database_tools/implementation/series_detector.cpp b/src/database/database_tools/implementation/series_detector.cpp index f0e3283f6b..e1d3c0c5e1 100644 --- a/src/database/database_tools/implementation/series_detector.cpp +++ b/src/database/database_tools/implementation/series_detector.cpp @@ -371,7 +371,7 @@ std::vector SeriesDetector::listCandidates(const Rules& rules) c timer.start(); const std::deque candidates = - evaluate(Database::IBackend &)>(m_db, [](Database::IBackend& backend) + evaluate(m_db, [](Database::IBackend& backend) { std::vector result; diff --git a/src/gui/desktop/quick_items/context_menu_manager.cpp b/src/gui/desktop/quick_items/context_menu_manager.cpp index 0a44f135c4..4a5da9a8a4 100644 --- a/src/gui/desktop/quick_items/context_menu_manager.cpp +++ b/src/gui/desktop/quick_items/context_menu_manager.cpp @@ -169,7 +169,7 @@ void ContextMenuManager::manageGroupsAction() { Database::IDatabase& db = m_project->getDatabase(); - const std::vector groupMembers = evaluate(Database::IBackend &)>(db, [this](Database::IBackend& backend) + const std::vector groupMembers = evaluate(db, [this](Database::IBackend& backend) { std::vector members; diff --git a/src/gui/desktop/utils/people_editor.cpp b/src/gui/desktop/utils/people_editor.cpp index e3f44a54d5..2da7007e8c 100644 --- a/src/gui/desktop/utils/people_editor.cpp +++ b/src/gui/desktop/utils/people_editor.cpp @@ -58,7 +58,7 @@ namespace bool wasPhotoAnalyzedAndHasNoFaces(Database::IDatabase& db, const Photo::Id& ph_id) { - return evaluate(db, [ph_id](Database::IBackend& backend) + return evaluate(db, [ph_id](Database::IBackend& backend) { const auto analysisState = backend.get(ph_id, FacesAnalysisState); @@ -68,7 +68,7 @@ namespace QString pathFor(Database::IDatabase& db, const Photo::Id& id) { - return evaluate(db, [id](Database::IBackend& backend) + return evaluate(db, [id](Database::IBackend& backend) { auto photo = backend.getPhotoDelta(id, {Photo::Field::Path}); @@ -173,7 +173,7 @@ class Recognizer: public IRecognizePerson { typedef std::tuple, std::vector> Result; - evaluate(db, [this](Database::IBackend& backend) + evaluate(db, [this](Database::IBackend& backend) { std::vector people_fingerprints; std::vector people; @@ -238,7 +238,7 @@ FaceEditor::PeopleData FaceEditor::findFaces(const OrientedImage& image, const P // photo not analyzed yet (no records in db) or analyzed and we have data in db if (facesNotFound == false) { - result = evaluate(m_db, [id](Database::IBackend& backend) + result = evaluate(m_db, [id](Database::IBackend& backend) { return backend.getPhotoDelta(id); }); @@ -262,7 +262,7 @@ FaceEditor::PeopleData FaceEditor::findFaces(const OrientedImage& image, const P else { // store face location and fingerprint in db and update ids - evaluate(m_db, [&result](Database::IBackend& backend) + evaluate(m_db, [&result](Database::IBackend& backend) { backend.update({result}); diff --git a/src/gui/desktop/utils/thumbnail_manager.cpp b/src/gui/desktop/utils/thumbnail_manager.cpp index 0b28c223b1..ce1a54e19d 100644 --- a/src/gui/desktop/utils/thumbnail_manager.cpp +++ b/src/gui/desktop/utils/thumbnail_manager.cpp @@ -67,7 +67,7 @@ void ThumbnailManager::fetch(const Photo::Id& id, const QSize& desired_size, con QByteArray dbThumb; if (m_db) // load thumbnail from db - dbThumb = evaluate(*m_db, [id](Database::IBackend& backend) + dbThumb = evaluate(*m_db, [id](Database::IBackend& backend) { return backend.readBlob(id, BlobType); }); @@ -78,7 +78,7 @@ void ThumbnailManager::fetch(const Photo::Id& id, const QSize& desired_size, con if (dbThumb.isNull()) { // load path to photo - const Photo::DataDelta photoData = evaluate(*m_db, [id](Database::IBackend& backend) + const Photo::DataDelta photoData = evaluate(*m_db, [id](Database::IBackend& backend) { return backend.getPhotoDelta(id); });