From b06b8cf8aed9b977193d4251b592dacc4c240f5a Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 3 Jan 2020 22:42:12 -0600 Subject: [PATCH] Database: add tags method for getting set of tag names The database class now separatly tracks tag information. So for the one place where all the inclusions were iterated over in order to build up a tag set, we now instead ask the database for this set directly. Related to issue #245 --- src/Database.cpp | 6 ++++++ src/Database.h | 1 + src/TagInfoDatabase.cpp | 15 +++++++++++++++ src/TagInfoDatabase.h | 3 +++ src/dom.cpp | 7 ++----- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index e19cd9af..a110045a 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -260,6 +260,12 @@ std::vector Database::files () const return all; } +//////////////////////////////////////////////////////////////////////////////// +std::set Database::tags () const +{ + return _tagInfoDatabase.tags (); +} + //////////////////////////////////////////////////////////////////////////////// // Return most recent line from database std::string Database::firstLine () diff --git a/src/Database.h b/src/Database.h index 3066e336..56960f33 100644 --- a/src/Database.h +++ b/src/Database.h @@ -97,6 +97,7 @@ public: void initialize (const std::string&, Journal& journal); void commit (); std::vector files () const; + std::set tags () const; std::string firstLine (); diff --git a/src/TagInfoDatabase.cpp b/src/TagInfoDatabase.cpp index cfa9aee0..9a68498a 100644 --- a/src/TagInfoDatabase.cpp +++ b/src/TagInfoDatabase.cpp @@ -74,6 +74,21 @@ void TagInfoDatabase::add (const std::string& tag, const TagInfo& tagInfo) _tagInformation.emplace (tag, tagInfo); } +/////////////////////////////////////////////////////////////////////////////// +// Return the current set of tag names +// +std::set TagInfoDatabase::tags () const +{ + std::set tags; + + for (auto& item : _tagInformation) + { + tags.insert (item.first); + } + + return tags; +} + /////////////////////////////////////////////////////////////////////////////// std::string TagInfoDatabase::toJson () { diff --git a/src/TagInfoDatabase.h b/src/TagInfoDatabase.h index c1707637..502d2c6d 100644 --- a/src/TagInfoDatabase.h +++ b/src/TagInfoDatabase.h @@ -27,6 +27,7 @@ #ifndef INCLUDED_TAGINFODATABASE #define INCLUDED_TAGINFODATABASE +#include #include #include #include @@ -39,6 +40,8 @@ public: void add (const std::string&, const TagInfo&); + std::set tags () const; + std::string toJson (); private: diff --git a/src/dom.cpp b/src/dom.cpp index 76e27f18..eea38438 100644 --- a/src/dom.cpp +++ b/src/dom.cpp @@ -177,11 +177,8 @@ bool domGet ( else if (pig.skipLiteral ("tag.")) { - // Generate a unique, ordered list of tags. - std::set tags; - for (auto& interval : getAllInclusions (database)) - for (auto& tag : interval.tags ()) - tags.insert (tag); + // get unique, ordered list of tags. + std::set tags = database.tags (); // dom.tag.count if (pig.skipLiteral ("count"))