Load only chats with known info in MessagesManager::load_dialogs.

This commit is contained in:
levlam 2021-09-26 19:38:27 +03:00
parent d882e222a7
commit c5a2e9a870
7 changed files with 33 additions and 22 deletions

View File

@ -15333,7 +15333,7 @@ bool MessagesManager::have_dialog(DialogId dialog_id) const {
return dialogs_.count(dialog_id) > 0;
}
void MessagesManager::load_dialogs(vector<DialogId> dialog_ids, Promise<Unit> &&promise) {
void MessagesManager::load_dialogs(vector<DialogId> dialog_ids, Promise<vector<DialogId>> &&promise) {
LOG(INFO) << "Load chats " << format::as_array(dialog_ids);
Dependencies dependencies;
@ -15344,13 +15344,14 @@ void MessagesManager::load_dialogs(vector<DialogId> dialog_ids, Promise<Unit> &&
}
resolve_dependencies_force(td_, dependencies, "load_dialogs");
td::remove_if(dialog_ids, [this](DialogId dialog_id) { return !have_dialog_info(dialog_id); });
for (auto dialog_id : dialog_ids) {
if (dialog_id.is_valid()) {
force_create_dialog(dialog_id, "load_dialogs");
}
force_create_dialog(dialog_id, "load_dialogs");
}
promise.set_value(Unit());
LOG(INFO) << "Loaded chats " << format::as_array(dialog_ids);
promise.set_value(std::move(dialog_ids));
}
bool MessagesManager::load_dialog(DialogId dialog_id, int left_tries, Promise<Unit> &&promise) {

View File

@ -514,7 +514,7 @@ class MessagesManager final : public Actor {
bool load_dialog(DialogId dialog_id, int left_tries, Promise<Unit> &&promise);
void load_dialogs(vector<DialogId> dialog_ids, Promise<Unit> &&promise);
void load_dialogs(vector<DialogId> dialog_ids, Promise<vector<DialogId>> &&promise);
void load_dialog_filter(DialogFilterId dialog_id, bool force, Promise<Unit> &&promise);

View File

@ -106,7 +106,10 @@ void RecentDialogList::load_dialogs(Promise<Unit> &&promise) {
}
if (!dialog_ids.empty()) {
if (G()->parameters().use_message_db) {
td_->messages_manager_->load_dialogs(std::move(dialog_ids), mpas.get_promise());
td_->messages_manager_->load_dialogs(
std::move(dialog_ids),
PromiseCreator::lambda(
[promise = mpas.get_promise()](vector<DialogId> dialog_ids) mutable { promise.set_value(Unit()); }));
} else {
td_->messages_manager_->get_dialogs_from_list(
DialogListId(FolderId::main()), 102,
@ -135,6 +138,7 @@ void RecentDialogList::on_load_dialogs(vector<string> &&found_dialogs) {
dialog_id = DialogId(to_integer<int64>(*it));
}
if (dialog_id.is_valid() && removed_dialog_ids_.count(dialog_id) == 0 &&
td_->messages_manager_->have_dialog_info(dialog_id) &&
td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
td_->messages_manager_->force_create_dialog(dialog_id, "recent dialog");
do_add_dialog(dialog_id);

View File

@ -264,11 +264,13 @@ void StorageManager::send_stats(FileStats &&stats, int32 dialog_limit, std::vect
stats.apply_dialog_limit(dialog_limit);
auto dialog_ids = stats.get_dialog_ids();
auto promise = PromiseCreator::lambda([promises = std::move(promises), stats = std::move(stats)](Unit) mutable {
for (auto &promise : promises) {
promise.set_value(FileStats(stats));
}
});
auto promise = PromiseCreator::lambda(
[promises = std::move(promises), stats = std::move(stats)](vector<DialogId> dialog_ids) mutable {
stats.apply_dialog_ids(dialog_ids);
for (auto &promise : promises) {
promise.set_value(FileStats(stats));
}
});
send_closure(G()->messages_manager(), &MessagesManager::load_dialogs, std::move(dialog_ids), std::move(promise));
}

View File

@ -366,9 +366,12 @@ void TopDialogManager::do_get_top_dialogs(GetTopDialogsQuery &&query) {
}
}
auto promise =
PromiseCreator::lambda([actor_id = actor_id(this), query = std::move(query), dialog_ids](Result<Unit>) mutable {
send_closure(actor_id, &TopDialogManager::on_load_dialogs, std::move(query), std::move(dialog_ids));
auto promise = PromiseCreator::lambda(
[actor_id = actor_id(this), query = std::move(query)](Result<vector<DialogId>> r_dialog_ids) mutable {
if (r_dialog_ids.is_error()) {
return query.promise.set_error(r_dialog_ids.move_as_error());
}
send_closure(actor_id, &TopDialogManager::on_load_dialogs, std::move(query), r_dialog_ids.move_as_ok());
});
td_->messages_manager_->load_dialogs(std::move(dialog_ids), std::move(promise));
}

View File

@ -10,6 +10,7 @@
#include "td/telegram/files/FileLoaderUtils.h"
#include "td/utils/algorithm.h"
#include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/misc.h"
@ -105,12 +106,11 @@ void FileStats::apply_dialog_limit(int32 limit) {
[](const auto &x, const auto &y) { return x.first > y.first; });
dialogs.resize(prefix);
std::unordered_set<DialogId, DialogIdHash> all_dialogs;
for (auto &dialog : dialogs) {
all_dialogs.insert(dialog.second);
}
apply_dialog_ids(transform(dialogs, [](const auto &dialog) { return dialog.second; }));
}
void FileStats::apply_dialog_ids(const vector<DialogId> &dialog_ids) {
std::unordered_set<DialogId, DialogIdHash> all_dialogs(dialog_ids.begin(), dialog_ids.end());
StatByType other_stats;
bool other_flag = false;
for (auto it = stat_by_owner_dialog_id_.begin(); it != stat_by_owner_dialog_id_.end();) {
@ -127,7 +127,7 @@ void FileStats::apply_dialog_limit(int32 limit) {
}
if (other_flag) {
DialogId other_dialog_id;
DialogId other_dialog_id; // prevents MSVC warning C4709: comma operator within array index expression
stat_by_owner_dialog_id_[other_dialog_id] = other_stats;
}
}

View File

@ -88,7 +88,6 @@ class FileStats {
friend StringBuilder &operator<<(StringBuilder &sb, const FileStats &file_stats);
public:
//FileStats() = default;
FileStats(bool need_all_files, bool split_by_owner_dialog_id)
: need_all_files_(need_all_files), split_by_owner_dialog_id_(split_by_owner_dialog_id) {
}
@ -99,6 +98,8 @@ class FileStats {
void apply_dialog_limit(int32 limit);
void apply_dialog_ids(const vector<DialogId> &dialog_ids);
tl_object_ptr<td_api::storageStatistics> get_storage_statistics_object() const;
vector<DialogId> get_dialog_ids() const;