Add task condition.

This commit is contained in:
amass 2024-02-17 23:21:19 +08:00
parent 379f54a797
commit 64c21878f5

View File

@ -47,9 +47,13 @@ Tasks Database::tasks() {
std::unordered_map<int, Task *> tasks; std::unordered_map<int, Task *> tasks;
for (auto iterator = ret.begin(); iterator != ret.end();) { for (auto iterator = ret.begin(); iterator != ret.end();) {
if (iterator->parentId >= 0) { if (iterator->parentId >= 0) {
auto parentTask = tasks.at(iterator->parentId); if (tasks.count(iterator->parentId) > 0) {
parentTask->children.push_back(*iterator); auto parentTask = tasks.at(iterator->parentId);
tasks.insert({iterator->id, &parentTask->children.back()}); parentTask->children.push_back(*iterator);
tasks.insert({iterator->id, &parentTask->children.back()});
} else {
LOG(warning) << "task`s parent id " << iterator->parentId << " not existed.";
}
iterator = ret.erase(iterator); iterator = ret.erase(iterator);
} else { } else {
tasks.insert({iterator->id, &(*iterator)}); tasks.insert({iterator->id, &(*iterator)});