Make TDB2.backlog non-public

The stats command gets this information from an API that will also work
for TaskChampion.  The sync command still accesses the field directly,
as the command must be completely rewritten for TaskChampion.
This commit is contained in:
Dustin J. Mitchell 2022-04-01 14:58:05 +00:00 committed by Tomas Babej
parent d699ce8cba
commit c8cfcec48b
6 changed files with 37 additions and 28 deletions

View file

@ -90,13 +90,8 @@ bool getDOM (const std::string& name, Variant& value)
if (name == "tw.syncneeded")
{
value = Variant (0);
for (const auto& line : Context::getContext ().tdb2.backlog.get_lines ())
{
if (line[0] == '{')
{
value = Variant (1);
break;
}
if (Context::getContext ().tdb2.num_local_changes () > 0) {
value = Variant (1);
}
return true;

View file

@ -1259,6 +1259,19 @@ bool TDB2::read_only ()
;
}
////////////////////////////////////////////////////////////////////////////////
int TDB2::num_local_changes ()
{
std::vector <std::string> lines = backlog.get_lines ();
return std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
}
////////////////////////////////////////////////////////////////////////////////
size_t TDB2::data_size ()
{
return pending._file.size () + completed._file.size () + undo._file.size () + backlog._file.size ();
}
////////////////////////////////////////////////////////////////////////////////
void TDB2::clear ()
{

View file

@ -135,6 +135,9 @@ public:
// Read-only mode.
bool read_only ();
int num_local_changes ();
size_t data_size ();
void clear ();
void dump ();
@ -152,6 +155,9 @@ public:
TF2 pending;
TF2 completed;
TF2 undo;
protected:
friend class CmdSync; // CmdSync accesses the backlog directly
TF2 backlog;
private:

View file

@ -63,18 +63,14 @@ int CmdStats::execute (std::string& output)
std::string dateformat = Context::getContext ().config.get ("dateformat");
// Go get the file sizes.
size_t dataSize = Context::getContext ().tdb2.pending._file.size ()
+ Context::getContext ().tdb2.completed._file.size ()
+ Context::getContext ().tdb2.undo._file.size ()
+ Context::getContext ().tdb2.backlog._file.size ();
size_t dataSize = Context::getContext ().tdb2.data_size ();
// Count the undo transactions.
std::vector <std::string> undoTxns = Context::getContext ().tdb2.undo.get_lines ();
int undoCount = std::count(undoTxns.begin(), undoTxns.end(), "---");
// Count the backlog transactions.
std::vector <std::string> backlogTxns = Context::getContext ().tdb2.backlog.get_lines ();
int backlogCount = std::count_if(backlogTxns.begin(), backlogTxns.end(), [](const auto& tx){ return tx.front() == '{'; });
int numLocalChanges = Context::getContext ().tdb2.num_local_changes ();
// Get all the tasks.
Filter filter;
@ -207,7 +203,7 @@ int CmdStats::execute (std::string& output)
row = view.addRow ();
view.set (row, 0, "Sync backlog transactions");
view.set (row, 1, backlogCount);
view.set (row, 1, numLocalChanges);
if (totalT)
{

View file

@ -210,8 +210,7 @@ void feedback_backlog ()
if (Context::getContext ().config.get ("taskd.server") != "" &&
Context::getContext ().verbose ("sync"))
{
std::vector <std::string> lines = Context::getContext ().tdb2.backlog.get_lines ();
int count = std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
int count = Context::getContext ().tdb2.num_local_changes ();
if (count)
Context::getContext ().footnote (format (count > 1 ? "There are {1} local changes. Sync required."
: "There is {1} local change. Sync required.", count));