Fix process_config.

GitOrigin-RevId: ea657dfc621fdf13a1641377a2bef6ddd396172a
This commit is contained in:
levlam 2018-03-08 18:01:45 +03:00
parent 34f6fd8942
commit c2dbb601cf
7 changed files with 40 additions and 12 deletions

View File

@ -671,7 +671,9 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
shared_config.set_option_integer("basic_group_size_max", config->chat_size_max_);
shared_config.set_option_integer("supergroup_size_max", config->megagroup_size_max_);
shared_config.set_option_integer("pinned_chat_count_max", config->pinned_dialogs_count_max_);
shared_config.set_option_string("t_me_url", config->me_url_prefix_);
if (is_from_main_dc || !shared_config.have_option("t_me_url")) {
shared_config.set_option_string("t_me_url", config->me_url_prefix_);
}
if (is_from_main_dc) {
if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0) {
G()->shared_config().set_option_integer("session_count", config->tmp_sessions_);
@ -680,15 +682,15 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
}
}
shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_);
shared_config.set_option_boolean("revoke_pm_inbox",
(config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0);
shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);
shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_);
if (is_from_main_dc) {
shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_);
shared_config.set_option_boolean("revoke_pm_inbox",
(config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0);
shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);
shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_);
shared_config.set_option_boolean("calls_enabled", config->phonecalls_enabled_);
}
shared_config.set_option_integer("call_ring_timeout_ms", config->call_ring_timeout_ms_);

View File

@ -42,6 +42,10 @@ void ConfigShared::set_option_string(Slice name, Slice value) {
}
}
bool ConfigShared::have_option(Slice name) const {
return config_pmc_->isset(name.str());
}
string ConfigShared::get_option(Slice name) const {
return config_pmc_->get(name.str());
}

View File

@ -34,6 +34,7 @@ class ConfigShared {
void set_option_integer(Slice name, int32 value);
void set_option_string(Slice name, Slice value);
bool have_option(Slice name) const;
string get_option(Slice name) const;
std::unordered_map<string, string> get_options(Slice prefix) const;
std::unordered_map<string, string> get_options() const;

View File

@ -162,6 +162,11 @@ class BinlogKeyValue : public KeyValueSyncInterface {
binlog_->add_raw_event(seq_no, std::move(event));
}
bool isset(const string &key) override {
auto lock = rw_mutex_.lock_read().move_as_ok();
return map_.count(key) > 0;
}
string get(const string &key) override {
auto lock = rw_mutex_.lock_read().move_as_ok();
auto it = map_.find(key);

View File

@ -9,6 +9,7 @@
#include "td/utils/common.h"
namespace td {
class KeyValueSyncInterface {
public:
// SeqNo is used to restore total order on all write queries.
@ -21,8 +22,14 @@ class KeyValueSyncInterface {
KeyValueSyncInterface(KeyValueSyncInterface &&) = default;
KeyValueSyncInterface &operator=(KeyValueSyncInterface &&) = default;
virtual ~KeyValueSyncInterface() = default;
virtual SeqNo set(string key, string value) = 0;
virtual SeqNo erase(const string &key) = 0;
virtual bool isset(const string &key) = 0;
virtual string get(const string &key) = 0;
virtual SeqNo erase(const string &key) = 0;
};
} // namespace td

View File

@ -5,6 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/db/binlog/ConcurrentBinlog.h"
#include "td/db/BinlogKeyValue.h"
#include "td/db/SqliteKeyValue.h"
@ -13,7 +15,7 @@
#include <memory>
namespace td {
class SqliteKeyValue;
using BinlogPmcBase = BinlogKeyValue<ConcurrentBinlog>;
using BinlogPmc = std::shared_ptr<BinlogPmcBase>;
using BinlogPmcPtr = BinlogPmcBase *;
@ -21,4 +23,5 @@ using BinlogPmcPtr = BinlogPmcBase *;
using BigPmcBase = SqliteKeyValue;
using BigPmc = std::unique_ptr<BigPmcBase>;
using BigPmcPtr = BigPmcBase *;
}; // namespace td

View File

@ -490,16 +490,22 @@ class OldFakeKeyValue : public KeyValueSyncInterface {
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 "";
return string();
}
private: