mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Create tag database from existing interval database on startup
- Closes #224 Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
eeb9bc4db3
commit
b15cddd562
2 changed files with 66 additions and 13 deletions
|
@ -375,22 +375,41 @@ void Database::initializeTagDatabase ()
|
|||
|
||||
if (!File::read (_location + "/tags.data", content))
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto intervals = getAllInclusions (*this);
|
||||
|
||||
auto* json = (json::object*) json::parse (content);
|
||||
|
||||
for (auto& pair : json->_data)
|
||||
{
|
||||
auto key = pair.first;
|
||||
auto* value = (json::object*) pair.second;
|
||||
auto iter = value->_data.find ("count");
|
||||
if (iter == value->_data.end ())
|
||||
if (intervals.empty ())
|
||||
{
|
||||
throw format ("Failed to find \"count\" member for tag \"{1}\" in tags database. Database corrupted?", key);
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Tag info database does not exist. Recreating from interval data..." << std::endl ;
|
||||
|
||||
for (auto& interval : intervals)
|
||||
{
|
||||
for (auto& tag : interval.tags ())
|
||||
{
|
||||
_tagInfoDatabase.incrementTag (tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto *json = (json::object *) json::parse (content);
|
||||
|
||||
for (auto &pair : json->_data)
|
||||
{
|
||||
auto key = pair.first;
|
||||
auto *value = (json::object *) pair.second;
|
||||
auto iter = value->_data.find ("count");
|
||||
|
||||
if (iter == value->_data.end ())
|
||||
{
|
||||
throw format ("Failed to find \"count\" member for tag \"{1}\" in tags database. Database corrupted?", key);
|
||||
}
|
||||
|
||||
auto number = dynamic_cast<json::number *> (iter->second);
|
||||
_tagInfoDatabase.add (key, TagInfo{(unsigned int) number->_dvalue});
|
||||
}
|
||||
auto number = dynamic_cast<json::number *> (iter->second);
|
||||
_tagInfoDatabase.add (key, TagInfo {(unsigned int) number->_dvalue});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue