From fcb765f9ae9262a11fa8bcbe9d852284de184e9f Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Thu, 29 Jul 2021 23:05:29 +0100 Subject: [PATCH] Optimise adding items to history --- far/changelog | 5 +++++ far/configdb.cpp | 8 ++++---- far/configdb.hpp | 11 ++++------- far/history.cpp | 9 +++------ far/vbuild.m4 | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/far/changelog b/far/changelog index 2e7dfbbea7..e9eaadfbc5 100644 --- a/far/changelog +++ b/far/changelog @@ -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 diff --git a/far/configdb.cpp b/far/configdb.cpp index f722f48a0d..ae23e12290 100644 --- a/far/configdb.cpp +++ b/far/configdb.cpp @@ -1922,8 +1922,8 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate static const stmt_init 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 ?2;"sv }, @@ -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; diff --git a/far/configdb.hpp b/far/configdb.hpp index dfeb4ad22a..9ac2f00651 100644 --- a/far/configdb.hpp +++ b/far/configdb.hpp @@ -450,16 +450,13 @@ class HistoryConfig: public representable, virtual public transactional string Data; }; - template [[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); - using value_type = enum_data; - return make_inline_enumerator([this, HistoryType, HistoryName = keep_alive(FWD(HistoryName)), Reverse](const bool Reset, value_type& Value) + return make_inline_enumerator([&](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] { @@ -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; diff --git a/far/history.cpp b/far/history.cpp index ac970d9175..236889ce27 100644 --- a/far/history.cpp +++ b/far/history.cpp @@ -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; @@ -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; @@ -761,7 +758,7 @@ bool History::GetSimilar(string &strStr, int LastCmdPartLength, bool bAppend) void History::GetAllSimilar(string_view const Str, function_ref 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)) { diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 3951fb1098..3fb524c7bd 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -5859 +5860