Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicer86 committed Jun 3, 2024
1 parent 82be041 commit 6394524
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/core/task_executor_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ class CORE_EXPORT WorkState

// Helper function.
// Run a task and wait for it to be finished.
template<typename R, typename E, typename T>
template<typename E, typename T>
[[nodiscard]]
auto evaluate(E& executor, const T& task)
{
using PTask = std::packaged_task<R>;

PTask p_task(task);
std::packaged_task p_task(task);

auto result_future = p_task.get_future();
ExecutorTraits<E, PTask>::exec(executor, std::move(p_task));
ExecutorTraits<E, decltype(p_task)>::exec(executor, std::move(p_task));

result_future.wait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ namespace

void perform() override
{
using namespace Photo;
auto data = evaluate<Photo::ExplicitDelta<Field::Flags, Field::PHash, Field::Path, Field::Geometry, Field::Tags>(Database::IBackend &)>(*m_storage, [this](Database::IBackend& backend)
auto data = evaluate(*m_storage, [this](Database::IBackend& backend)

Check warning on line 141 in src/database/database_tools/implementation/photos_analyzer.cpp

View check run for this annotation

Codecov / codecov/patch

src/database/database_tools/implementation/photos_analyzer.cpp#L141

Added line #L141 was not covered by tests
{
using namespace Photo;
return backend.getPhotoDelta<Field::Flags, Field::PHash, Field::Path, Field::Geometry, Field::Tags>(m_id);

Check warning on line 144 in src/database/database_tools/implementation/photos_analyzer.cpp

View check run for this annotation

Codecov / codecov/patch

src/database/database_tools/implementation/photos_analyzer.cpp#L144

Added line #L144 was not covered by tests
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ std::vector<GroupCandidate> SeriesDetector::listCandidates(const Rules& rules) c
timer.start();

const std::deque<ExplicitDelta> candidates =
evaluate<std::deque<ExplicitDelta>(Database::IBackend &)>(m_db, [](Database::IBackend& backend)
evaluate(m_db, [](Database::IBackend& backend)

Check warning on line 374 in src/database/database_tools/implementation/series_detector.cpp

View check run for this annotation

Codecov / codecov/patch

src/database/database_tools/implementation/series_detector.cpp#L374

Added line #L374 was not covered by tests
{
std::vector<GroupCandidate> result;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/desktop/quick_items/context_menu_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void ContextMenuManager::manageGroupsAction()
{
Database::IDatabase& db = m_project->getDatabase();

const std::vector<ExplicitDelta> groupMembers = evaluate<std::vector<ExplicitDelta>(Database::IBackend &)>(db, [this](Database::IBackend& backend)
const std::vector<ExplicitDelta> groupMembers = evaluate(db, [this](Database::IBackend& backend)
{
std::vector<ExplicitDelta> members;

Expand Down
10 changes: 5 additions & 5 deletions src/gui/desktop/utils/people_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace

bool wasPhotoAnalyzedAndHasNoFaces(Database::IDatabase& db, const Photo::Id& ph_id)
{
return evaluate<bool(Database::IBackend &)>(db, [ph_id](Database::IBackend& backend)
return evaluate(db, [ph_id](Database::IBackend& backend)
{
const auto analysisState = backend.get(ph_id, FacesAnalysisState);

Expand All @@ -68,7 +68,7 @@ namespace

QString pathFor(Database::IDatabase& db, const Photo::Id& id)
{
return evaluate<QString(Database::IBackend &)>(db, [id](Database::IBackend& backend)
return evaluate(db, [id](Database::IBackend& backend)
{
auto photo = backend.getPhotoDelta(id, {Photo::Field::Path});

Expand Down Expand Up @@ -173,7 +173,7 @@ class Recognizer: public IRecognizePerson
{
typedef std::tuple<std::vector<Person::Fingerprint>, std::vector<Person::Id>> Result;

evaluate<void(Database::IBackend &)>(db, [this](Database::IBackend& backend)
evaluate(db, [this](Database::IBackend& backend)
{
std::vector<Person::Fingerprint> people_fingerprints;
std::vector<Person::Id> people;
Expand Down Expand Up @@ -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<FaceEditor::PeopleData(Database::IBackend &)>(m_db, [id](Database::IBackend& backend)
result = evaluate(m_db, [id](Database::IBackend& backend)
{
return backend.getPhotoDelta<Photo::Field::People>(id);
});
Expand All @@ -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<void(Database::IBackend &)>(m_db, [&result](Database::IBackend& backend)
evaluate(m_db, [&result](Database::IBackend& backend)
{
backend.update({result});

Expand Down
4 changes: 2 additions & 2 deletions src/gui/desktop/utils/thumbnail_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QByteArray(Database::IBackend &)>(*m_db, [id](Database::IBackend& backend)
dbThumb = evaluate(*m_db, [id](Database::IBackend& backend)
{
return backend.readBlob(id, BlobType);
});
Expand All @@ -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<Photo::DataDelta(Database::IBackend &)>(*m_db, [id](Database::IBackend& backend)
const Photo::DataDelta photoData = evaluate(*m_db, [id](Database::IBackend& backend)
{
return backend.getPhotoDelta<Photo::Field::Path>(id);
});
Expand Down

0 comments on commit 6394524

Please sign in to comment.