small refactor

This commit is contained in:
Yarik Briukhovetskyi 2024-10-03 18:25:03 +02:00 committed by GitHub
parent af9590a03c
commit 95d2991166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 13 deletions

View File

@ -23,7 +23,7 @@ bool CompareEndTime::operator()(const QueryToTrack& a, const QueryToTrack& b) co
if (a.endtime != b.endtime) if (a.endtime != b.endtime)
return a.endtime < b.endtime; return a.endtime < b.endtime;
else else
return a.query->getClientInfo().current_query_id < b.query->getClientInfo().current_query_id; return a.query < b.query;
} }
CancellationChecker::CancellationChecker() : stop_thread(false) CancellationChecker::CancellationChecker() : stop_thread(false)
@ -48,23 +48,23 @@ void CancellationChecker::cancelTask(std::shared_ptr<QueryStatus> query, CancelR
bool CancellationChecker::removeQueryFromSet(std::shared_ptr<QueryStatus> query) bool CancellationChecker::removeQueryFromSet(std::shared_ptr<QueryStatus> query)
{ {
for (auto it = querySet.begin(); it != querySet.end();) auto it = std::find_if(querySet.begin(), querySet.end(), [&](const QueryToTrack& task) {
return task.query == query;
});
if (it != querySet.end())
{ {
if (it->query == query) LOG_TRACE(getLogger("CancellationChecker"), "Removing query {} from done tasks", query->getInfo().query);
{ querySet.erase(it);
LOG_TRACE(getLogger("CancellationChecker"), "Removing query {} from done tasks", query->getInfo().query); return true;
it = querySet.erase(it);
return true;
}
else
++it;
} }
return false; return false;
} }
void CancellationChecker::appendTask(const std::shared_ptr<QueryStatus> & query, const UInt64 & timeout) void CancellationChecker::appendTask(const std::shared_ptr<QueryStatus> & query, const Int64 & timeout)
{ {
if (timeout > 0) // Avoid cases when the timeout is less or equal zero if (timeout <= 0) // Avoid cases when the timeout is less or equal zero
{ {
LOG_TRACE(getLogger("CancellationChecker"), "Did not add the task because the timeout is 0. Query: {}", query->getInfo().query); LOG_TRACE(getLogger("CancellationChecker"), "Did not add the task because the timeout is 0. Query: {}", query->getInfo().query);
return; return;

View File

@ -56,7 +56,7 @@ public:
CancellationChecker& operator=(const CancellationChecker&) = delete; CancellationChecker& operator=(const CancellationChecker&) = delete;
// Method to add a new task to the multiset // Method to add a new task to the multiset
void appendTask(const std::shared_ptr<QueryStatus> & query, const UInt64 & timeout); void appendTask(const std::shared_ptr<QueryStatus> & query, const Int64 & timeout);
// Used when some task is done // Used when some task is done
void appendDoneTasks(const std::shared_ptr<QueryStatus> & query); void appendDoneTasks(const std::shared_ptr<QueryStatus> & query);