Add get_user_full_force.

GitOrigin-RevId: 3486e0097a343b996a943555acfcba5afdbc61a9
This commit is contained in:
levlam 2019-09-19 04:21:40 +03:00
parent f934ccbd50
commit 7619eaa0f0
2 changed files with 60 additions and 6 deletions

View File

@ -4452,7 +4452,7 @@ void ContactsManager::on_update_profile_success(int32 flags, const string &first
<< "Wrong last name \"" << u->last_name << "\", expected \"" << last_name << '"'; << "Wrong last name \"" << u->last_name << "\", expected \"" << last_name << '"';
if ((flags & ACCOUNT_UPDATE_ABOUT) != 0) { if ((flags & ACCOUNT_UPDATE_ABOUT) != 0) {
UserFull *user_full = get_user_full(my_user_id); UserFull *user_full = get_user_full_force(my_user_id);
if (user_full != nullptr && user_full->is_inited) { if (user_full != nullptr && user_full->is_inited) {
user_full->about = about; user_full->about = about;
user_full->is_changed = true; user_full->is_changed = true;
@ -6710,6 +6710,56 @@ string ContactsManager::get_user_full_database_value(const UserFull *user_full)
return log_event_store(*user_full).as_slice().str(); return log_event_store(*user_full).as_slice().str();
} }
void ContactsManager::on_load_user_full_from_database(UserId user_id, string value) {
LOG(INFO) << "Successfully loaded full " << user_id << " of size " << value.size() << " from database";
// G()->td_db()->get_sqlite_pmc()->erase(get_user_full_database_key(user_id), Auto());
// return;
if (get_user_full(user_id) != nullptr || value.empty()) {
return;
}
UserFull *user_full = &users_full_[user_id];
auto status = log_event_parse(*user_full, value);
if (status.is_error()) {
// can't happen unless database is broken
LOG(ERROR) << "Repair broken full " << user_id << ' ' << format::as_hex_dump<4>(Slice(value));
// just clean all known data about the user and pretend that there was nothing in the database
users_full_.erase(user_id);
G()->td_db()->get_sqlite_pmc()->erase(get_user_full_database_key(user_id), Auto());
return;
}
Dependencies dependencies;
dependencies.user_ids.insert(user_id);
td_->messages_manager_->resolve_dependencies_force(dependencies);
update_user_full(user_full, user_id, true);
}
ContactsManager::UserFull *ContactsManager::get_user_full_force(UserId user_id) {
if (!user_id.is_valid()) {
return nullptr;
}
UserFull *c = get_user_full(user_id);
if (c != nullptr) {
return c;
}
if (!G()->parameters().use_chat_info_db) {
return nullptr;
}
if (!unavailable_user_fulls_.insert(user_id).second) {
return nullptr;
}
LOG(INFO) << "Trying to load full " << user_id << " from database";
on_load_user_full_from_database(user_id,
G()->td_db()->get_sqlite_sync_pmc()->get(get_user_full_database_key(user_id)));
return get_user_full(user_id);
}
void ContactsManager::save_chat_full(ChatFull *chat_full, ChatId chat_id) { void ContactsManager::save_chat_full(ChatFull *chat_full, ChatId chat_id) {
if (!G()->parameters().use_chat_info_db) { if (!G()->parameters().use_chat_info_db) {
return; return;
@ -7147,6 +7197,7 @@ void ContactsManager::update_secret_chat(SecretChat *c, SecretChatId secret_chat
void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool from_database) { void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool from_database) {
CHECK(user_full != nullptr); CHECK(user_full != nullptr);
unavailable_user_fulls_.erase(user_id); // don't needed anymore
if (user_full->is_common_chat_count_changed) { if (user_full->is_common_chat_count_changed) {
td_->messages_manager_->drop_common_dialogs_cache(user_id); td_->messages_manager_->drop_common_dialogs_cache(user_id);
user_full->is_common_chat_count_changed = false; user_full->is_common_chat_count_changed = false;
@ -7893,7 +7944,7 @@ void ContactsManager::on_update_user_blocked(UserId user_id, bool is_blocked) {
return; return;
} }
UserFull *user_full = get_user_full(user_id); UserFull *user_full = get_user_full_force(user_id);
if (user_full == nullptr) { if (user_full == nullptr) {
return; return;
} }
@ -7916,7 +7967,7 @@ void ContactsManager::on_update_user_common_chat_count(UserId user_id, int32 com
return; return;
} }
UserFull *user_full = get_user_full(user_id); UserFull *user_full = get_user_full_force(user_id);
if (user_full == nullptr) { if (user_full == nullptr) {
return; return;
} }
@ -8028,7 +8079,7 @@ void ContactsManager::on_update_user_links(User *u, UserId user_id, LinkState ou
} }
void ContactsManager::drop_user_full(UserId user_id) { void ContactsManager::drop_user_full(UserId user_id) {
auto user_full = get_user_full(user_id); auto user_full = get_user_full_force(user_id);
if (user_full == nullptr) { if (user_full == nullptr) {
return; return;
} }
@ -9766,7 +9817,7 @@ bool ContactsManager::get_user_full(UserId user_id, Promise<Unit> &&promise) {
return false; return false;
} }
auto user_full = get_user_full(user_id); auto user_full = get_user_full_force(user_id);
if (user_full == nullptr || !user_full->is_inited) { if (user_full == nullptr || !user_full->is_inited) {
auto input_user = get_input_user(user_id); auto input_user = get_input_user(user_id);
if (input_user == nullptr) { if (input_user == nullptr) {
@ -10559,7 +10610,7 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id,
if (!td_->auth_manager_->is_bot() && is_user_bot(user_id)) { if (!td_->auth_manager_->is_bot() && is_user_bot(user_id)) {
// get BotInfo through UserFull // get BotInfo through UserFull
auto user = get_user(user_id); auto user = get_user(user_id);
auto user_full = get_user_full(user_id); auto user_full = get_user_full_force(user_id);
if (user_full == nullptr || user_full->is_bot_info_expired(user->bot_info_version)) { if (user_full == nullptr || user_full->is_bot_info_expired(user->bot_info_version)) {
if (force) { if (force) {
LOG(ERROR) << "Can't find cached UserFull"; LOG(ERROR) << "Can't find cached UserFull";

View File

@ -890,6 +890,7 @@ class ContactsManager : public Actor {
const UserFull *get_user_full(UserId user_id) const; const UserFull *get_user_full(UserId user_id) const;
UserFull *get_user_full(UserId user_id); UserFull *get_user_full(UserId user_id);
UserFull *get_user_full_force(UserId user_id);
void send_get_user_full_query(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, void send_get_user_full_query(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user,
Promise<Unit> &&promise, const char *source); Promise<Unit> &&promise, const char *source);
@ -1051,6 +1052,7 @@ class ContactsManager : public Actor {
void save_user_full(UserFull *user_full, UserId user_id); void save_user_full(UserFull *user_full, UserId user_id);
static string get_user_full_database_key(UserId user_id); static string get_user_full_database_key(UserId user_id);
static string get_user_full_database_value(const UserFull *user_full); static string get_user_full_database_value(const UserFull *user_full);
void on_load_user_full_from_database(UserId user_id, string value);
void save_chat_full(ChatFull *chat_full, ChatId chat_id); void save_chat_full(ChatFull *chat_full, ChatId chat_id);
static string get_chat_full_database_key(ChatId chat_id); static string get_chat_full_database_key(ChatId chat_id);
@ -1223,6 +1225,7 @@ class ContactsManager : public Actor {
std::unordered_map<UserId, vector<Promise<Unit>>, UserIdHash> load_user_from_database_queries_; std::unordered_map<UserId, vector<Promise<Unit>>, UserIdHash> load_user_from_database_queries_;
std::unordered_set<UserId, UserIdHash> loaded_from_database_users_; std::unordered_set<UserId, UserIdHash> loaded_from_database_users_;
std::unordered_set<UserId, UserIdHash> unavailable_user_fulls_;
std::unordered_map<ChatId, vector<Promise<Unit>>, ChatIdHash> load_chat_from_database_queries_; std::unordered_map<ChatId, vector<Promise<Unit>>, ChatIdHash> load_chat_from_database_queries_;
std::unordered_set<ChatId, ChatIdHash> loaded_from_database_chats_; std::unordered_set<ChatId, ChatIdHash> loaded_from_database_chats_;