From a2a7b44ad629d5e8f49a46a0cb0fbd0dd15af5c9 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 7 Jan 2019 01:58:09 +0300 Subject: [PATCH] Use KeyValueSyncInterface in ConfigShared. GitOrigin-RevId: 8670b43b1dc9d5619fee2081aa98ddc936820c64 --- td/telegram/ConfigShared.cpp | 2 +- td/telegram/ConfigShared.h | 7 +++---- td/telegram/TdDb.cpp | 2 +- td/telegram/TdDb.h | 2 +- tddb/td/db/BinlogKeyValue.h | 4 ++-- tddb/td/db/KeyValueSyncInterface.h | 7 +++++++ tddb/td/db/binlog/ConcurrentBinlog.h | 1 + test/secret.cpp | 26 -------------------------- 8 files changed, 16 insertions(+), 35 deletions(-) diff --git a/td/telegram/ConfigShared.cpp b/td/telegram/ConfigShared.cpp index 81cdbf32..4957176e 100644 --- a/td/telegram/ConfigShared.cpp +++ b/td/telegram/ConfigShared.cpp @@ -13,7 +13,7 @@ namespace td { -ConfigShared::ConfigShared(std::shared_ptr> config_pmc, unique_ptr callback) +ConfigShared::ConfigShared(std::shared_ptr config_pmc, unique_ptr callback) : config_pmc_(std::move(config_pmc)), callback_(std::move(callback)) { for (auto key_value : config_pmc_->get_all()) { on_option_updated(key_value.first); diff --git a/td/telegram/ConfigShared.h b/td/telegram/ConfigShared.h index 4dd42c74..2f14e754 100644 --- a/td/telegram/ConfigShared.h +++ b/td/telegram/ConfigShared.h @@ -8,8 +8,7 @@ #include "td/telegram/td_api.h" -#include "td/db/binlog/ConcurrentBinlog.h" -#include "td/db/BinlogKeyValue.h" +#include "td/db/KeyValueSyncInterface.h" #include "td/utils/common.h" #include "td/utils/Slice.h" @@ -30,7 +29,7 @@ class ConfigShared { virtual void on_option_updated(const string &name, const string &value) const = 0; }; - ConfigShared(std::shared_ptr> config_pmc, unique_ptr callback); + ConfigShared(std::shared_ptr config_pmc, unique_ptr callback); void set_option_boolean(Slice name, bool value); void set_option_empty(Slice name); @@ -51,7 +50,7 @@ class ConfigShared { static tl_object_ptr get_option_value_object(Slice value); private: - std::shared_ptr> config_pmc_; + std::shared_ptr config_pmc_; unique_ptr callback_; bool set_option(Slice name, Slice value); diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 5a0aa4b0..6f6b068c 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -144,7 +144,7 @@ std::shared_ptr TdDb::get_binlog_pmc_shared() { return binlog_pmc_; } -std::shared_ptr> TdDb::get_config_pmc_shared() { +std::shared_ptr TdDb::get_config_pmc_shared() { return config_pmc_; } diff --git a/td/telegram/TdDb.h b/td/telegram/TdDb.h index 002b35b6..5e90058a 100644 --- a/td/telegram/TdDb.h +++ b/td/telegram/TdDb.h @@ -69,7 +69,7 @@ class TdDb { ConcurrentBinlog *get_binlog(); std::shared_ptr get_binlog_pmc_shared(); - std::shared_ptr> get_config_pmc_shared(); + std::shared_ptr get_config_pmc_shared(); BinlogKeyValue *get_binlog_pmc(); BinlogKeyValue *get_config_pmc(); diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 5cdce46e..56a1c568 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -183,7 +183,7 @@ class BinlogKeyValue : public KeyValueSyncInterface { binlog_->lazy_sync(std::move(promise)); } - std::unordered_map prefix_get(Slice prefix) { + std::unordered_map prefix_get(Slice prefix) override { // TODO: optimize with std::map? auto lock = rw_mutex_.lock_write().move_as_ok(); std::unordered_map res; @@ -195,7 +195,7 @@ class BinlogKeyValue : public KeyValueSyncInterface { return res; } - std::unordered_map get_all() { + std::unordered_map get_all() override { auto lock = rw_mutex_.lock_write().move_as_ok(); std::unordered_map res; for (const auto &kv : map_) { diff --git a/tddb/td/db/KeyValueSyncInterface.h b/tddb/td/db/KeyValueSyncInterface.h index eb59c179..8da5b96a 100644 --- a/tddb/td/db/KeyValueSyncInterface.h +++ b/tddb/td/db/KeyValueSyncInterface.h @@ -7,6 +7,9 @@ #pragma once #include "td/utils/common.h" +#include "td/utils/Slice.h" + +#include namespace td { @@ -29,6 +32,10 @@ class KeyValueSyncInterface { virtual string get(const string &key) = 0; + virtual std::unordered_map prefix_get(Slice prefix) = 0; + + virtual std::unordered_map get_all() = 0; + virtual SeqNo erase(const string &key) = 0; }; diff --git a/tddb/td/db/binlog/ConcurrentBinlog.h b/tddb/td/db/binlog/ConcurrentBinlog.h index f36cc1bd..18a14201 100644 --- a/tddb/td/db/binlog/ConcurrentBinlog.h +++ b/tddb/td/db/binlog/ConcurrentBinlog.h @@ -65,4 +65,5 @@ class ConcurrentBinlog : public BinlogInterface { string path_; std::atomic last_id_; }; + } // namespace td diff --git a/test/secret.cpp b/test/secret.cpp index 6e6ffcda..175d8e78 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -471,32 +471,6 @@ class FakeBinlog }; using FakeKeyValue = BinlogKeyValue; -class OldFakeKeyValue : public KeyValueSyncInterface { - SeqNo set(string key, string value) override { - kv_[key] = value; - return 0; - } - - SeqNo erase(const string &key) override { - kv_.erase(key); - return 0; - } - - bool isset(const string &key) override { - return kv_.count(key) > 0; - } - - string get(const string &key) override { - auto it = kv_.find(key); - if (it != kv_.end()) { - return it->second; - } - return string(); - } - - private: - std::map kv_; -}; class Master; class FakeSecretChatContext : public SecretChatActor::Context {