mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Duration
- Removed legacy duration value mapping, which causes much performance degradation.
This commit is contained in:
parent
f0cc0151b7
commit
7665d13d42
6 changed files with 17 additions and 129 deletions
|
@ -61,31 +61,48 @@ static struct
|
|||
{"fortnight", 14 * DAY, true},
|
||||
{"hours", 1 * HOUR, false},
|
||||
{"hour", 1 * HOUR, true},
|
||||
{"hrs", 1 * HOUR, true},
|
||||
{"hr", 1 * HOUR, true},
|
||||
{"h", 1 * HOUR, false},
|
||||
{"minutes", 1 * MINUTE, false},
|
||||
{"minute", 1 * MINUTE, false},
|
||||
{"mins", 1 * MINUTE, false},
|
||||
{"min", 1 * MINUTE, false},
|
||||
{"monthly", 30 * DAY, true},
|
||||
{"months", 30 * DAY, false},
|
||||
{"month", 30 * DAY, true},
|
||||
{"mnths", 30 * DAY, false},
|
||||
{"mths", 30 * DAY, false},
|
||||
{"mth", 30 * DAY, false},
|
||||
{"mos", 30 * DAY, false},
|
||||
{"mo", 30 * DAY, false},
|
||||
{"m", 30 * DAY, false},
|
||||
{"quarterly", 91 * DAY, true},
|
||||
{"quarters", 91 * DAY, false},
|
||||
{"quarter", 91 * DAY, true},
|
||||
{"qrtrs", 91 * DAY, false},
|
||||
{"qtrs", 91 * DAY, false},
|
||||
{"qtr", 91 * DAY, false},
|
||||
{"q", 91 * DAY, false},
|
||||
{"semiannual", 183 * DAY, true},
|
||||
{"sennight", 14 * DAY, false},
|
||||
{"seconds", 1 * SECOND, false},
|
||||
{"second", 1 * SECOND, true},
|
||||
{"secs", 1 * SECOND, true},
|
||||
{"sec", 1 * SECOND, true},
|
||||
{"s", 1 * SECOND, false},
|
||||
{"weekdays", 1 * DAY, true},
|
||||
{"weekly", 7 * DAY, true},
|
||||
{"weeks", 7 * DAY, false},
|
||||
{"week", 7 * DAY, true},
|
||||
{"wks", 7 * DAY, true},
|
||||
{"wk", 7 * DAY, true},
|
||||
{"w", 7 * DAY, false},
|
||||
{"yearly", 365 * DAY, true},
|
||||
{"years", 365 * DAY, false},
|
||||
{"year", 365 * DAY, true},
|
||||
{"yrs", 365 * DAY, true},
|
||||
{"yr", 365 * DAY, true},
|
||||
{"y", 365 * DAY, false},
|
||||
};
|
||||
|
||||
|
|
|
@ -580,7 +580,6 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */)
|
|||
{
|
||||
// Ensure the task is consistent, and provide defaults if necessary.
|
||||
task.validate (false);
|
||||
task.upgradeLegacyValues ();
|
||||
std::string uuid = task.get ("uuid");
|
||||
|
||||
// Get the unmodified task as reference, so the hook can compare.
|
||||
|
|
80
src/Task.cpp
80
src/Task.cpp
|
@ -565,7 +565,6 @@ void Task::parse (const std::string& input)
|
|||
nl.getQuoted ('"', value))
|
||||
{
|
||||
legacyAttributeMap (name);
|
||||
legacyValueMap (name, value);
|
||||
|
||||
if (name.substr (0, 11) == "annotation_")
|
||||
++annotation_count;
|
||||
|
@ -586,8 +585,6 @@ void Task::parse (const std::string& input)
|
|||
parseJSON (copy);
|
||||
else
|
||||
throw std::string (STRING_RECORD_NOT_FF4);
|
||||
|
||||
upgradeLegacyValues ();
|
||||
}
|
||||
|
||||
catch (const std::string&)
|
||||
|
@ -719,8 +716,6 @@ void Task::parseJSON (const std::string& line)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
upgradeLegacyValues ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2219,78 +2214,3 @@ void Task::modify (modType type, bool text_required /* = false */)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::upgradeLegacyValues ()
|
||||
{
|
||||
// 2.4.0 Update recurrence values.
|
||||
if (has ("recur"))
|
||||
{
|
||||
std::string value = get ("recur");
|
||||
if (value != "")
|
||||
{
|
||||
std::string new_value = value;
|
||||
upgradeLegacyValue (new_value);
|
||||
|
||||
if (new_value != value)
|
||||
{
|
||||
set ("recur", new_value);
|
||||
context.debug (format ("Legacy upgrade: recur {1} --> {2}", value, new_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2.4.0 Update UDA duration values.
|
||||
Config::const_iterator name;
|
||||
for (name = context.config.begin (); name != context.config.end (); ++name)
|
||||
{
|
||||
if (name->first.substr (0, 4) == "uda." &&
|
||||
name->first.find (".type") != std::string::npos)
|
||||
{
|
||||
if (name->second == "duration")
|
||||
{
|
||||
std::string::size_type period = name->first.find ('.', 4);
|
||||
if (period != std::string::npos)
|
||||
{
|
||||
std::string uda = name->first.substr (4, period - 4);
|
||||
std::string value = get (uda);
|
||||
std::string new_value = value;
|
||||
upgradeLegacyValue (new_value);
|
||||
|
||||
if (new_value != value)
|
||||
{
|
||||
set ("recur", new_value);
|
||||
context.debug (format ("Legacy upgrade: UDA {1}, {2} --> {3}", uda, value, new_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::upgradeLegacyValue (std::string& value)
|
||||
{
|
||||
std::string::size_type len = value.length ();
|
||||
std::string::size_type p;
|
||||
|
||||
if (value == "-") value = "0s";
|
||||
else if ((p = value.find ("hr")) != std::string::npos && p == len - 2) value = value.substr (0, p) + "h";
|
||||
else if ((p = value.find ("hrs")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "h";
|
||||
else if ((p = value.find ("mins")) != std::string::npos && p == len - 4) value = value.substr (0, p) + "min";
|
||||
else if ((p = value.find ("mnths")) != std::string::npos && p == len - 5) value = value.substr (0, p) + "mo";
|
||||
else if ((p = value.find ("mos")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "mo";
|
||||
else if ((p = value.find ("mth")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "mo";
|
||||
else if ((p = value.find ("mths")) != std::string::npos && p == len - 4) value = value.substr (0, p) + "mo";
|
||||
else if ((p = value.find ("qrtrs")) != std::string::npos && p == len - 5) value = value.substr (0, p) + "q";
|
||||
else if ((p = value.find ("qtr")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "q";
|
||||
else if ((p = value.find ("qtrs")) != std::string::npos && p == len - 4) value = value.substr (0, p) + "q";
|
||||
else if ((p = value.find ("sec")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "s";
|
||||
else if ((p = value.find ("secs")) != std::string::npos && p == len - 4) value = value.substr (0, p) + "s";
|
||||
else if ((p = value.find ("wk")) != std::string::npos && p == len - 2) value = value.substr (0, p) + "w";
|
||||
else if ((p = value.find ("wks")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "w";
|
||||
else if ((p = value.find ("yr")) != std::string::npos && p == len - 2) value = value.substr (0, p) + "y";
|
||||
else if ((p = value.find ("yrs")) != std::string::npos && p == len - 3) value = value.substr (0, p) + "y";
|
||||
|
||||
// It is not an error to have a non-legacy value.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -154,7 +154,6 @@ public:
|
|||
|
||||
enum modType {modReplace, modPrepend, modAppend, modAnnotate};
|
||||
void modify (modType, bool text_required = false);
|
||||
void upgradeLegacyValues ();
|
||||
|
||||
private:
|
||||
int determineVersion (const std::string&);
|
||||
|
@ -163,7 +162,6 @@ private:
|
|||
void validate_before (const std::string&, const std::string&);
|
||||
const std::string encode (const std::string&) const;
|
||||
const std::string decode (const std::string&) const;
|
||||
void upgradeLegacyValue (std::string&);
|
||||
|
||||
public:
|
||||
float urgency_priority () const;
|
||||
|
|
|
@ -166,48 +166,3 @@ void legacyAttributeMap (std::string& name)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO Is this needed, given Task::upgradeLegacyValues?
|
||||
void legacyValueMap (const std::string& name, std::string& value)
|
||||
{
|
||||
// 2014-07-03: One-time initialization value mapping.
|
||||
static std::map <std::string, std::string> mapping;
|
||||
if (mapping.size () == 0)
|
||||
{
|
||||
mapping["hrs"] = "hours";
|
||||
mapping["hr"] = "hours";
|
||||
mapping["mins"] = "minutes";
|
||||
mapping["mnths"] = "months";
|
||||
mapping["mths"] = "months";
|
||||
mapping["mth"] = "months";
|
||||
mapping["mos"] = "months";
|
||||
mapping["m"] = "months"; // ?
|
||||
mapping["qrtrs"] = "quarters";
|
||||
mapping["qtrs"] = "quarters";
|
||||
mapping["qtr"] = "quarters";
|
||||
mapping["secs"] = "seconds";
|
||||
mapping["sec"] = "seconds";
|
||||
mapping["s"] = "seconds"; // ?
|
||||
mapping["wks"] = "weeks";
|
||||
mapping["wk"] = "weeks";
|
||||
mapping["yrs"] = "years";
|
||||
mapping["yr"] = "years";
|
||||
}
|
||||
|
||||
if (name == "recur")
|
||||
{
|
||||
std::size_t letter = value.find_first_not_of ("0123456789.");
|
||||
if (letter == std::string::npos)
|
||||
letter = 0;
|
||||
|
||||
std::map <std::string, std::string>::iterator i = mapping.find (value.substr (letter));
|
||||
if (i != mapping.end ())
|
||||
{
|
||||
if (letter)
|
||||
value = value.substr (0, letter) + i->second;
|
||||
else
|
||||
value = i->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -86,7 +86,6 @@ std::string legacyCheckForDeprecatedColor ();
|
|||
std::string legacyCheckForDeprecatedVariables ();
|
||||
std::string legacyCheckForDeprecatedColumns ();
|
||||
void legacyAttributeMap (std::string&);
|
||||
void legacyValueMap (const std::string&, std::string&);
|
||||
|
||||
// list template
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue