Use KeyValueSyncInterface in ConfigShared.
GitOrigin-RevId: 8670b43b1dc9d5619fee2081aa98ddc936820c64
This commit is contained in:
parent
aaae105785
commit
a2a7b44ad6
@ -13,7 +13,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
ConfigShared::ConfigShared(std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> config_pmc, unique_ptr<Callback> callback)
|
||||
ConfigShared::ConfigShared(std::shared_ptr<KeyValueSyncInterface> config_pmc, unique_ptr<Callback> 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);
|
||||
|
@ -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<BinlogKeyValue<ConcurrentBinlog>> config_pmc, unique_ptr<Callback> callback);
|
||||
ConfigShared(std::shared_ptr<KeyValueSyncInterface> config_pmc, unique_ptr<Callback> 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<td_api::OptionValue> get_option_value_object(Slice value);
|
||||
|
||||
private:
|
||||
std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> config_pmc_;
|
||||
std::shared_ptr<KeyValueSyncInterface> config_pmc_;
|
||||
unique_ptr<Callback> callback_;
|
||||
|
||||
bool set_option(Slice name, Slice value);
|
||||
|
@ -144,7 +144,7 @@ std::shared_ptr<KeyValueSyncInterface> TdDb::get_binlog_pmc_shared() {
|
||||
return binlog_pmc_;
|
||||
}
|
||||
|
||||
std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> TdDb::get_config_pmc_shared() {
|
||||
std::shared_ptr<KeyValueSyncInterface> TdDb::get_config_pmc_shared() {
|
||||
return config_pmc_;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class TdDb {
|
||||
ConcurrentBinlog *get_binlog();
|
||||
|
||||
std::shared_ptr<KeyValueSyncInterface> get_binlog_pmc_shared();
|
||||
std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> get_config_pmc_shared();
|
||||
std::shared_ptr<KeyValueSyncInterface> get_config_pmc_shared();
|
||||
BinlogKeyValue<ConcurrentBinlog> *get_binlog_pmc();
|
||||
BinlogKeyValue<ConcurrentBinlog> *get_config_pmc();
|
||||
|
||||
|
@ -183,7 +183,7 @@ class BinlogKeyValue : public KeyValueSyncInterface {
|
||||
binlog_->lazy_sync(std::move(promise));
|
||||
}
|
||||
|
||||
std::unordered_map<string, string> prefix_get(Slice prefix) {
|
||||
std::unordered_map<string, string> prefix_get(Slice prefix) override {
|
||||
// TODO: optimize with std::map?
|
||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||
std::unordered_map<string, string> res;
|
||||
@ -195,7 +195,7 @@ class BinlogKeyValue : public KeyValueSyncInterface {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::unordered_map<string, string> get_all() {
|
||||
std::unordered_map<string, string> get_all() override {
|
||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||
std::unordered_map<string, string> res;
|
||||
for (const auto &kv : map_) {
|
||||
|
@ -7,6 +7,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -29,6 +32,10 @@ class KeyValueSyncInterface {
|
||||
|
||||
virtual string get(const string &key) = 0;
|
||||
|
||||
virtual std::unordered_map<string, string> prefix_get(Slice prefix) = 0;
|
||||
|
||||
virtual std::unordered_map<string, string> get_all() = 0;
|
||||
|
||||
virtual SeqNo erase(const string &key) = 0;
|
||||
};
|
||||
|
||||
|
@ -65,4 +65,5 @@ class ConcurrentBinlog : public BinlogInterface {
|
||||
string path_;
|
||||
std::atomic<uint64> last_id_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -471,32 +471,6 @@ class FakeBinlog
|
||||
};
|
||||
|
||||
using FakeKeyValue = BinlogKeyValue<BinlogInterface>;
|
||||
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<string, string> kv_;
|
||||
};
|
||||
|
||||
class Master;
|
||||
class FakeSecretChatContext : public SecretChatActor::Context {
|
||||
|
Reference in New Issue
Block a user