Disable DownloadManager database without message database.
This commit is contained in:
parent
4acfae167f
commit
1d647c7049
@ -332,6 +332,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
return file_info.size == 0 ? max(file_info.downloaded_size + 1, file_info.expected_size) : file_info.size;
|
return file_info.size == 0 ? max(file_info.downloaded_size + 1, file_info.expected_size) : file_info.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_database_enabled() {
|
||||||
|
return G()->parameters().use_message_db;
|
||||||
|
}
|
||||||
|
|
||||||
static string pmc_key(const FileInfo &file_info) {
|
static string pmc_key(const FileInfo &file_info) {
|
||||||
return PSTRING() << "dlds#" << file_info.download_id;
|
return PSTRING() << "dlds#" << file_info.download_id;
|
||||||
}
|
}
|
||||||
@ -341,6 +345,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
}
|
}
|
||||||
file_info.need_save_to_db = false;
|
file_info.need_save_to_db = false;
|
||||||
|
|
||||||
|
if (!is_database_enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Saving to download database file " << file_info.file_id << '/' << file_info.internal_file_id
|
LOG(INFO) << "Saving to download database file " << file_info.file_id << '/' << file_info.internal_file_id
|
||||||
<< " with is_paused = " << file_info.is_paused;
|
<< " with is_paused = " << file_info.is_paused;
|
||||||
FileDownloadInDb to_save;
|
FileDownloadInDb to_save;
|
||||||
@ -362,26 +370,31 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto serialized_counter = G()->td_db()->get_binlog_pmc()->get("dlds_counter");
|
if (is_database_enabled()) {
|
||||||
if (!serialized_counter.empty()) {
|
auto serialized_counter = G()->td_db()->get_binlog_pmc()->get("dlds_counter");
|
||||||
log_event_parse(sent_counters_, serialized_counter).ensure();
|
if (!serialized_counter.empty()) {
|
||||||
if (sent_counters_.downloaded_size == sent_counters_.total_size || sent_counters_.total_size == 0) {
|
log_event_parse(sent_counters_, serialized_counter).ensure();
|
||||||
G()->td_db()->get_binlog_pmc()->erase("dlds_counter");
|
if (sent_counters_.downloaded_size == sent_counters_.total_size || sent_counters_.total_size == 0) {
|
||||||
sent_counters_ = Counters();
|
G()->td_db()->get_binlog_pmc()->erase("dlds_counter");
|
||||||
} else {
|
sent_counters_ = Counters();
|
||||||
callback_->update_counters(sent_counters_);
|
} else {
|
||||||
|
callback_->update_counters(sent_counters_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto downloads_in_kv = G()->td_db()->get_binlog_pmc()->prefix_get("dlds#");
|
auto downloads_in_kv = G()->td_db()->get_binlog_pmc()->prefix_get("dlds#");
|
||||||
for (auto &it : downloads_in_kv) {
|
for (auto &it : downloads_in_kv) {
|
||||||
Slice key = it.first;
|
Slice key = it.first;
|
||||||
Slice value = it.second;
|
Slice value = it.second;
|
||||||
FileDownloadInDb in_db;
|
FileDownloadInDb in_db;
|
||||||
log_event_parse(in_db, value).ensure();
|
log_event_parse(in_db, value).ensure();
|
||||||
CHECK(in_db.download_id == to_integer_safe<int64>(key).ok());
|
CHECK(in_db.download_id == to_integer_safe<int64>(key).ok());
|
||||||
max_download_id_ = max(in_db.download_id, max_download_id_);
|
max_download_id_ = max(in_db.download_id, max_download_id_);
|
||||||
add_file_from_db(in_db);
|
add_file_from_db(in_db);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
G()->td_db()->get_binlog_pmc()->erase("dlds_counter");
|
||||||
|
G()->td_db()->get_binlog_pmc()->erase_by_prefix("dlds#");
|
||||||
}
|
}
|
||||||
|
|
||||||
is_started_ = true;
|
is_started_ = true;
|
||||||
@ -531,6 +544,12 @@ class DownloadManagerImpl final : public DownloadManager {
|
|||||||
set_timeout_in(60.0);
|
set_timeout_in(60.0);
|
||||||
}
|
}
|
||||||
sent_counters_ = counters_;
|
sent_counters_ = counters_;
|
||||||
|
if (counters_ == Counters()) {
|
||||||
|
G()->td_db()->get_binlog_pmc()->erase("dlds_counter");
|
||||||
|
} else {
|
||||||
|
G()->td_db()->get_binlog_pmc()->set("dlds_counter", log_event_store(counters_).as_slice().str());
|
||||||
|
}
|
||||||
|
|
||||||
callback_->update_counters(counters_);
|
callback_->update_counters(counters_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,6 +355,8 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters ¶meters, con
|
|||||||
binlog_pmc.erase_by_prefix("unread_dialog_count");
|
binlog_pmc.erase_by_prefix("unread_dialog_count");
|
||||||
binlog_pmc.erase("sponsored_dialog_id");
|
binlog_pmc.erase("sponsored_dialog_id");
|
||||||
binlog_pmc.erase_by_prefix("top_dialogs");
|
binlog_pmc.erase_by_prefix("top_dialogs");
|
||||||
|
binlog_pmc.erase("dlds_counter");
|
||||||
|
binlog_pmc.erase_by_prefix("dlds#");
|
||||||
}
|
}
|
||||||
if (user_version == 0) {
|
if (user_version == 0) {
|
||||||
binlog_pmc.erase("next_contacts_sync_date");
|
binlog_pmc.erase("next_contacts_sync_date");
|
||||||
|
Loading…
Reference in New Issue
Block a user