Skip to content

Commit

Permalink
Optimise adding items to history
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 29, 2021
1 parent a00819b commit fcb765f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 29.07.2021 23:04:52 +0100 - build 5860

1. Optimise adding items to history.

--------------------------------------------------------------------------------
drkns 29.07.2021 19:41:27 +0100 - build 5859

Expand Down
8 changes: 4 additions & 4 deletions far/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,8 +1922,8 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate

static const stmt_init<statement_id> Statements[]
{
{ stmtEnum, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 ORDER BY time;"sv },
{ stmtEnumDesc, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 ORDER BY lock DESC, time DESC;"sv },
{ stmtEnum, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 AND (?3 OR name COLLATE NOCASE =?4) ORDER BY time;"sv },
{ stmtEnumDesc, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 AND (?3 OR name COLLATE NOCASE =?4) ORDER BY lock DESC, time DESC;"sv },
{ stmtDel, "DELETE FROM history WHERE id=?1;"sv },
{ stmtDeleteOldUnlocked, "DELETE FROM history WHERE kind=?1 AND key=?2 AND lock=0 AND time<?3 AND id NOT IN (SELECT id FROM history WHERE kind=?1 AND key=?2 ORDER BY lock DESC, time DESC LIMIT ?4);"sv },
{ stmtEnumLargeHistories, "SELECT key FROM (SELECT key, num FROM (SELECT key, count(id) as num FROM history WHERE kind=?1 GROUP BY key)) WHERE num > ?2;"sv },
Expand Down Expand Up @@ -2011,13 +2011,13 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate
return AutoStatement(Reverse? stmtEnumDesc : stmtEnum);
}

bool Enum(const bool Reset, const unsigned int TypeHistory, const string_view HistoryName, unsigned long long& id, string& Name, history_record_type& Type, bool& Lock, os::chrono::time_point& Time, string& strUuid, string& strFile, string& strData, const bool Reverse) override
bool Enum(const bool Reset, const unsigned int TypeHistory, const string_view HistoryName, const string_view ItemName, unsigned long long& id, string& Name, history_record_type& Type, bool& Lock, os::chrono::time_point& Time, string& strUuid, string& strFile, string& strData, const bool Reverse) override
{
WaitAllAsync();
auto Stmt = EnumStmt(Reverse);

if (Reset)
Stmt->Reset().Bind(TypeHistory, HistoryName);
Stmt->Reset().Bind(TypeHistory, HistoryName, ItemName.empty(), ItemName);

if (!Stmt->Step())
return false;
Expand Down
11 changes: 4 additions & 7 deletions far/configdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,13 @@ class HistoryConfig: public representable, virtual public transactional
string Data;
};

template<typename type>
[[nodiscard]]
auto Enumerator(unsigned int HistoryType, type&& HistoryName, bool Reverse = false)
auto Enumerator(unsigned int const HistoryType, string_view const HistoryName, string_view const ItemName = {}, bool const Reverse = false)
{
static_assert(std::is_convertible_v<type, string_view>);

using value_type = enum_data;
return make_inline_enumerator<value_type>([this, HistoryType, HistoryName = keep_alive(FWD(HistoryName)), Reverse](const bool Reset, value_type& Value)
return make_inline_enumerator<value_type>([&](const bool Reset, value_type& Value)
{
return Enum(Reset, HistoryType, HistoryName.get(), Value.Id, Value.Name, Value.Type, Value.Lock, Value.Time, Value.Uuid, Value.File, Value.Data, Reverse);
return Enum(Reset, HistoryType, HistoryName, ItemName, Value.Id, Value.Name, Value.Type, Value.Lock, Value.Time, Value.Uuid, Value.File, Value.Data, Reverse);
},
[this, Reverse]
{
Expand Down Expand Up @@ -487,7 +484,7 @@ class HistoryConfig: public representable, virtual public transactional
private:
//command,view,edit,folder,dialog history
[[nodiscard]]
virtual bool Enum(bool Reset, unsigned int TypeHistory, string_view HistoryName, unsigned long long& id, string& strName, history_record_type& Type, bool& Lock, os::chrono::time_point& Time, string& strUuid, string& strFile, string& strData, bool Reverse) = 0;
virtual bool Enum(bool Reset, unsigned int TypeHistory, string_view HistoryName, string_view ItemName, unsigned long long& id, string& strName, history_record_type& Type, bool& Lock, os::chrono::time_point& Time, string& strUuid, string& strFile, string& strData, bool Reverse) = 0;
virtual void CloseEnum(bool Reverse) const = 0;
[[nodiscard]]
virtual bool EnumLargeHistories(bool Reset, unsigned int TypeHistory, int MinimumEntries, string& strHistoryName) = 0;
Expand Down
9 changes: 3 additions & 6 deletions far/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,11 @@ void History::AddToHistory(string_view const Str, history_record_type const Type

const bool ignore_data = m_TypeHistory == HISTORYTYPE_CMD;

for (const auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName))
for (const auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName, Str))
{
if (!EqualType(Type, i.Type))
continue;

if (!equal_icase(Str, i.Name))
continue;

if (!equal_icase(strUuid, i.Uuid))
continue;

Expand Down Expand Up @@ -275,7 +272,7 @@ history_return_type History::ProcessMenu(string& strStr, UUID* const Uuid, strin
return L""s;
};

for (auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName, m_TypeHistory == HISTORYTYPE_DIALOG))
for (auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName, {}, m_TypeHistory == HISTORYTYPE_DIALOG))
{
if (!is_known_record(i.Time))
continue;
Expand Down Expand Up @@ -761,7 +758,7 @@ bool History::GetSimilar(string &strStr, int LastCmdPartLength, bool bAppend)

void History::GetAllSimilar(string_view const Str, function_ref<void(string_view Name, unsigned long long Id, bool IsLocked)> const Callback) const
{
for (const auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName, true))
for (const auto& i: HistoryCfgRef()->Enumerator(m_TypeHistory, m_HistoryName, {}, true))
{
if (is_known_record(i.Time) && starts_with_icase(i.Name, Str))
{
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5859
5860

0 comments on commit fcb765f

Please sign in to comment.