Remove unused mutex
This commit is contained in:
parent
604df72790
commit
eb28f728be
@ -281,7 +281,7 @@ class GetWebAuthorizationsQuery : public Td::ResultHandler {
|
||||
|
||||
results->websites_.push_back(make_tl_object<td_api::connectedWebsite>(
|
||||
authorization->hash_, authorization->domain_,
|
||||
td->contacts_manager_->get_user_id_object_internal(bot_user_id, "GetWebAuthorizationsQuery"), authorization->browser_,
|
||||
td->contacts_manager_->get_user_id_object(bot_user_id, "GetWebAuthorizationsQuery"), authorization->browser_,
|
||||
authorization->platform_, authorization->date_created_, authorization->date_active_, authorization->ip_,
|
||||
authorization->region_));
|
||||
}
|
||||
@ -2664,17 +2664,17 @@ tl_object_ptr<td_api::chatStatisticsSupergroup> ContactsManager::convert_megagro
|
||||
|
||||
auto top_senders = transform(std::move(obj->top_posters_), [this](auto &&top_poster) {
|
||||
return td_api::make_object<td_api::chatStatisticsMessageSenderInfo>(
|
||||
this->get_user_id_object_internal(UserId(top_poster->user_id_), "get_top_senders"), top_poster->messages_,
|
||||
this->get_user_id_object(UserId(top_poster->user_id_), "get_top_senders"), top_poster->messages_,
|
||||
top_poster->avg_chars_);
|
||||
});
|
||||
auto top_administrators = transform(std::move(obj->top_admins_), [this](auto &&top_admin) {
|
||||
return td_api::make_object<td_api::chatStatisticsAdministratorActionsInfo>(
|
||||
this->get_user_id_object_internal(UserId(top_admin->user_id_), "get_top_administrators"), top_admin->deleted_,
|
||||
this->get_user_id_object(UserId(top_admin->user_id_), "get_top_administrators"), top_admin->deleted_,
|
||||
top_admin->kicked_, top_admin->banned_);
|
||||
});
|
||||
auto top_inviters = transform(std::move(obj->top_inviters_), [this](auto &&top_inviter) {
|
||||
return td_api::make_object<td_api::chatStatisticsInviterInfo>(
|
||||
this->get_user_id_object_internal(UserId(top_inviter->user_id_), "get_top_inviters"), top_inviter->invitations_);
|
||||
this->get_user_id_object(UserId(top_inviter->user_id_), "get_top_inviters"), top_inviter->invitations_);
|
||||
});
|
||||
|
||||
return make_tl_object<td_api::chatStatisticsSupergroup>(
|
||||
@ -4879,7 +4879,7 @@ void ContactsManager::on_load_imported_contacts_finished() {
|
||||
LOG(INFO) << "Finished to load " << all_imported_contacts_.size() << " imported contacts";
|
||||
|
||||
for (const auto &contact : all_imported_contacts_) {
|
||||
get_user_id_object_internal(contact.get_user_id(), "on_load_imported_contacts_finished"); // to ensure updateUser
|
||||
get_user_id_object(contact.get_user_id(), "on_load_imported_contacts_finished"); // to ensure updateUser
|
||||
}
|
||||
|
||||
if (need_clear_imported_contacts_) {
|
||||
@ -6854,7 +6854,7 @@ void ContactsManager::on_imported_contacts(int64 random_id, vector<UserId> impor
|
||||
std::unordered_map<size_t, int32> unique_id_to_unimported_contact_invites;
|
||||
for (size_t i = 0; i < add_size; i++) {
|
||||
auto unique_id = imported_contacts_pos_[i];
|
||||
get_user_id_object_internal(imported_contact_user_ids[i], "on_imported_contacts"); // to ensure updateUser
|
||||
get_user_id_object(imported_contact_user_ids[i], "on_imported_contacts"); // to ensure updateUser
|
||||
all_imported_contacts_[unique_id].set_user_id(imported_contact_user_ids[i]);
|
||||
unique_id_to_unimported_contact_invites[unique_id] = unimported_contact_invites[i];
|
||||
}
|
||||
@ -8180,7 +8180,7 @@ void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) {
|
||||
log_event_parse(log_event, event.data_).ensure();
|
||||
|
||||
auto secret_chat_id = log_event.secret_chat_id;
|
||||
if (have_secret_chat_internal(secret_chat_id)) {
|
||||
if (have_secret_chat(secret_chat_id)) {
|
||||
LOG(ERROR) << "Skip adding already added " << secret_chat_id;
|
||||
binlog_erase(G()->td_db()->get_binlog(), event.id_);
|
||||
return;
|
||||
@ -9044,7 +9044,7 @@ void ContactsManager::update_user_full(UserFull *user_full, UserId user_id, bool
|
||||
CHECK(u == nullptr || u->is_update_user_sent);
|
||||
}
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateUserFullInfo>(get_user_id_object_internal(user_id, "updateUserFullInfo"),
|
||||
make_tl_object<td_api::updateUserFullInfo>(get_user_id_object(user_id, "updateUserFullInfo"),
|
||||
get_user_full_info_object(user_id, user_full)));
|
||||
user_full->need_send_update = false;
|
||||
}
|
||||
@ -9084,7 +9084,7 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, bool
|
||||
}
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateBasicGroupFullInfo>(get_basic_group_id_object_internal(chat_id, "update_chat_full"),
|
||||
make_tl_object<td_api::updateBasicGroupFullInfo>(get_basic_group_id_object(chat_id, "update_chat_full"),
|
||||
get_basic_group_full_info_object(chat_full)));
|
||||
chat_full->need_send_update = false;
|
||||
}
|
||||
@ -9135,7 +9135,7 @@ void ContactsManager::update_channel_full(ChannelFull *channel_full, ChannelId c
|
||||
}
|
||||
send_closure(
|
||||
G()->td(), &Td::send_update,
|
||||
make_tl_object<td_api::updateSupergroupFullInfo>(get_supergroup_id_object_internal(channel_id, "update_channel_full"),
|
||||
make_tl_object<td_api::updateSupergroupFullInfo>(get_supergroup_id_object(channel_id, "update_channel_full"),
|
||||
get_supergroup_full_info_object(channel_full)));
|
||||
channel_full->need_send_update = false;
|
||||
}
|
||||
@ -10510,8 +10510,8 @@ tl_object_ptr<td_api::chatMember> ContactsManager::get_chat_member_object(
|
||||
const DialogParticipant &dialog_participant) const {
|
||||
UserId participant_user_id = dialog_participant.user_id;
|
||||
return td_api::make_object<td_api::chatMember>(
|
||||
get_user_id_object_internal(participant_user_id, "chatMember.user_id"),
|
||||
get_user_id_object_internal(dialog_participant.inviter_user_id, "chatMember.inviter_user_id"),
|
||||
get_user_id_object(participant_user_id, "chatMember.user_id"),
|
||||
get_user_id_object(dialog_participant.inviter_user_id, "chatMember.inviter_user_id"),
|
||||
dialog_participant.joined_date, dialog_participant.status.get_chat_member_status_object(),
|
||||
get_bot_info_object(participant_user_id));
|
||||
}
|
||||
@ -13209,11 +13209,6 @@ void ContactsManager::send_get_channel_full_query(ChannelFull *channel_full, Cha
|
||||
}
|
||||
|
||||
bool ContactsManager::have_secret_chat(SecretChatId secret_chat_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return have_secret_chat_internal(secret_chat_id);
|
||||
}
|
||||
|
||||
bool ContactsManager::have_secret_chat_internal(SecretChatId secret_chat_id) const {
|
||||
return secret_chats_.count(secret_chat_id) > 0;
|
||||
}
|
||||
|
||||
@ -13244,12 +13239,11 @@ ContactsManager::SecretChat *ContactsManager::get_secret_chat(SecretChatId secre
|
||||
|
||||
bool ContactsManager::get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise) {
|
||||
if (!secret_chat_id.is_valid()) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
promise.set_error(Status::Error(6, "Invalid secret chat identifier"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!have_secret_chat_internal(secret_chat_id)) {
|
||||
if (!have_secret_chat(secret_chat_id)) {
|
||||
if (!force && G()->parameters().use_chat_info_db) {
|
||||
send_closure_later(actor_id(this), &ContactsManager::load_secret_chat_from_database, nullptr, secret_chat_id,
|
||||
std::move(promise));
|
||||
@ -13267,7 +13261,6 @@ bool ContactsManager::get_secret_chat(SecretChatId secret_chat_id, bool force, P
|
||||
void ContactsManager::on_update_secret_chat(SecretChatId secret_chat_id, int64 access_hash, UserId user_id,
|
||||
SecretChatState state, bool is_outbound, int32 ttl, int32 date,
|
||||
string key_hash, int32 layer, FolderId initial_folder_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
LOG(INFO) << "Update " << secret_chat_id << " with " << user_id << " and access_hash " << access_hash;
|
||||
auto *secret_chat = add_secret_chat(secret_chat_id);
|
||||
if (access_hash != secret_chat->access_hash) {
|
||||
@ -13320,12 +13313,6 @@ void ContactsManager::on_update_secret_chat(SecretChatId secret_chat_id, int64 a
|
||||
|
||||
std::pair<int32, vector<UserId>> ContactsManager::search_among_users(const vector<UserId> &user_ids,
|
||||
const string &query, int32 limit) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return search_among_users_internal(user_ids, query, limit);
|
||||
}
|
||||
|
||||
std::pair<int32, vector<UserId>> ContactsManager::search_among_users_internal(const vector<UserId> &user_ids,
|
||||
const string &query, int32 limit) {
|
||||
Hints hints; // TODO cache Hints
|
||||
|
||||
for (auto user_id : user_ids) {
|
||||
@ -13344,7 +13331,6 @@ std::pair<int32, vector<UserId>> ContactsManager::search_among_users_internal(co
|
||||
|
||||
DialogParticipant ContactsManager::get_chat_participant(ChatId chat_id, UserId user_id, bool force,
|
||||
Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
LOG(INFO) << "Trying to get " << user_id << " as member of " << chat_id;
|
||||
if (force) {
|
||||
promise.set_value(Unit());
|
||||
@ -13366,7 +13352,6 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
|
||||
DialogParticipantsFilter filter,
|
||||
bool force,
|
||||
Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (limit < 0) {
|
||||
promise.set_error(Status::Error(3, "Parameter limit must be non-negative"));
|
||||
return {};
|
||||
@ -13414,13 +13399,12 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
|
||||
}
|
||||
|
||||
int32 total_count;
|
||||
std::tie(total_count, user_ids) = search_among_users_internal(user_ids, query, limit);
|
||||
std::tie(total_count, user_ids) = search_among_users(user_ids, query, limit);
|
||||
return {total_count, transform(user_ids, [&](UserId user_id) { return *get_chat_participant(chat_full, user_id); })};
|
||||
}
|
||||
|
||||
DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id, UserId user_id, int64 &random_id,
|
||||
bool force, Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
LOG(INFO) << "Trying to get " << user_id << " as member of " << channel_id << " with random_id " << random_id;
|
||||
if (random_id != 0) {
|
||||
// request has already been sent before
|
||||
@ -13483,7 +13467,6 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id,
|
||||
std::pair<int32, vector<DialogParticipant>> ContactsManager::get_channel_participants(
|
||||
ChannelId channel_id, const tl_object_ptr<td_api::SupergroupMembersFilter> &filter, const string &additional_query,
|
||||
int32 offset, int32 limit, int32 additional_limit, int64 &random_id, bool force, Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (random_id != 0) {
|
||||
// request has already been sent before
|
||||
auto it = received_channel_participants_.find(random_id);
|
||||
@ -13497,7 +13480,7 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::get_channel_partici
|
||||
}
|
||||
|
||||
auto user_ids = transform(result.second, [](const auto &participant) { return participant.user_id; });
|
||||
std::pair<int32, vector<UserId>> result_user_ids = search_among_users_internal(user_ids, additional_query, additional_limit);
|
||||
std::pair<int32, vector<UserId>> result_user_ids = search_among_users(user_ids, additional_query, additional_limit);
|
||||
|
||||
result.first = result_user_ids.first;
|
||||
std::unordered_set<UserId, UserIdHash> result_user_ids_set(result_user_ids.second.begin(),
|
||||
@ -13563,7 +13546,6 @@ void ContactsManager::send_get_channel_participants_query(ChannelId channel_id,
|
||||
|
||||
vector<DialogAdministrator> ContactsManager::get_dialog_administrators(DialogId dialog_id, int left_tries,
|
||||
Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto it = dialog_administrators_.find(dialog_id);
|
||||
if (it != dialog_administrators_.end()) {
|
||||
promise.set_value(Unit());
|
||||
@ -14170,11 +14152,6 @@ td_api::object_ptr<td_api::updateUser> ContactsManager::get_update_unknown_user_
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_user_id_object(UserId user_id, const char *source) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_user_id_object_internal(user_id, source);
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_user_id_object_internal(UserId user_id, const char *source) const {
|
||||
if (user_id.is_valid() && get_user(user_id) == nullptr && unknown_users_.count(user_id) == 0) {
|
||||
LOG(ERROR) << "Have no info about " << user_id << " from " << source;
|
||||
unknown_users_.insert(user_id);
|
||||
@ -14184,7 +14161,6 @@ int32 ContactsManager::get_user_id_object_internal(UserId user_id, const char *s
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_user_object(user_id, get_user(user_id));
|
||||
}
|
||||
|
||||
@ -14210,30 +14186,18 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
|
||||
}
|
||||
|
||||
vector<int32> ContactsManager::get_user_ids_object(const vector<UserId> &user_ids, const char *source) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_user_ids_object_internal(user_ids, source);
|
||||
}
|
||||
|
||||
vector<int32> ContactsManager::get_user_ids_object_internal(const vector<UserId> &user_ids, const char *source) const {
|
||||
return transform(user_ids, [this, source](UserId user_id) { return get_user_id_object_internal(user_id, source); });
|
||||
return transform(user_ids, [this, source](UserId user_id) { return get_user_id_object(user_id, source); });
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::users> ContactsManager::get_users_object(int32 total_count,
|
||||
const vector<UserId> &user_ids) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_users_object_internal(total_count, user_ids);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::users> ContactsManager::get_users_object_internal(int32 total_count,
|
||||
const vector<UserId> &user_ids) const {
|
||||
if (total_count == -1) {
|
||||
total_count = narrow_cast<int32>(user_ids.size());
|
||||
}
|
||||
return td_api::make_object<td_api::users>(total_count, get_user_ids_object_internal(user_ids, "get_users_object"));
|
||||
return td_api::make_object<td_api::users>(total_count, get_user_ids_object(user_ids, "get_users_object"));
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::userFullInfo> ContactsManager::get_user_full_info_object(UserId user_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_user_full_info_object(user_id, get_user_full(user_id));
|
||||
}
|
||||
|
||||
@ -14255,11 +14219,6 @@ td_api::object_ptr<td_api::updateBasicGroup> ContactsManager::get_update_unknown
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_basic_group_id_object(ChatId chat_id, const char *source) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_basic_group_id_object_internal(chat_id, source);
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_basic_group_id_object_internal(ChatId chat_id, const char *source) const {
|
||||
if (chat_id.is_valid() && get_chat(chat_id) == nullptr && unknown_chats_.count(chat_id) == 0) {
|
||||
LOG(ERROR) << "Have no info about " << chat_id << " from " << source;
|
||||
unknown_chats_.insert(chat_id);
|
||||
@ -14269,7 +14228,6 @@ int32 ContactsManager::get_basic_group_id_object_internal(ChatId chat_id, const
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object(ChatId chat_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_basic_group_object(chat_id, get_chat(chat_id));
|
||||
}
|
||||
|
||||
@ -14286,11 +14244,10 @@ tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object(ChatId
|
||||
tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object_const(ChatId chat_id, const Chat *c) const {
|
||||
return make_tl_object<td_api::basicGroup>(
|
||||
chat_id.get(), c->participant_count, get_chat_status(c).get_chat_member_status_object(), c->is_active,
|
||||
get_supergroup_id_object_internal(c->migrated_to_channel_id, "get_basic_group_object"));
|
||||
get_supergroup_id_object(c->migrated_to_channel_id, "get_basic_group_object"));
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_info_object(ChatId chat_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_basic_group_full_info_object(get_chat_full(chat_id));
|
||||
}
|
||||
|
||||
@ -14299,7 +14256,7 @@ tl_object_ptr<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_
|
||||
CHECK(chat_full != nullptr);
|
||||
return make_tl_object<td_api::basicGroupFullInfo>(
|
||||
get_chat_photo_object(td_->file_manager_.get(), chat_full->photo), chat_full->description,
|
||||
get_user_id_object_internal(chat_full->creator_user_id, "basicGroupFullInfo"),
|
||||
get_user_id_object(chat_full->creator_user_id, "basicGroupFullInfo"),
|
||||
transform(chat_full->participants,
|
||||
[this](const DialogParticipant &chat_participant) { return get_chat_member_object(chat_participant); }),
|
||||
chat_full->invite_link);
|
||||
@ -14313,11 +14270,6 @@ td_api::object_ptr<td_api::updateSupergroup> ContactsManager::get_update_unknown
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_supergroup_id_object(ChannelId channel_id, const char *source) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_supergroup_id_object_internal(channel_id, source);
|
||||
}
|
||||
|
||||
int32 ContactsManager::get_supergroup_id_object_internal(ChannelId channel_id, const char *source) const {
|
||||
if (channel_id.is_valid() && get_channel(channel_id) == nullptr && unknown_channels_.count(channel_id) == 0) {
|
||||
LOG(ERROR) << "Have no info about " << channel_id << " received from " << source;
|
||||
unknown_channels_.insert(channel_id);
|
||||
@ -14327,7 +14279,6 @@ int32 ContactsManager::get_supergroup_id_object_internal(ChannelId channel_id, c
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::supergroup> ContactsManager::get_supergroup_object(ChannelId channel_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_supergroup_object(channel_id, get_channel(channel_id));
|
||||
}
|
||||
|
||||
@ -14342,7 +14293,6 @@ tl_object_ptr<td_api::supergroup> ContactsManager::get_supergroup_object(Channel
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_info_object(ChannelId channel_id) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return get_supergroup_full_info_object(get_channel_full(channel_id));
|
||||
}
|
||||
|
||||
@ -14363,7 +14313,7 @@ tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_i
|
||||
channel_full->can_set_sticker_set, channel_full->can_set_location, channel_full->can_view_statistics,
|
||||
channel_full->is_all_history_available, channel_full->sticker_set_id.get(),
|
||||
channel_full->location.get_chat_location_object(), channel_full->invite_link,
|
||||
get_basic_group_id_object_internal(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"),
|
||||
get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"),
|
||||
channel_full->migrated_from_max_message_id.get());
|
||||
}
|
||||
|
||||
@ -14414,7 +14364,7 @@ tl_object_ptr<td_api::secretChat> ContactsManager::get_secret_chat_object(Secret
|
||||
tl_object_ptr<td_api::secretChat> ContactsManager::get_secret_chat_object_const(SecretChatId secret_chat_id,
|
||||
const SecretChat *secret_chat) const {
|
||||
return td_api::make_object<td_api::secretChat>(
|
||||
secret_chat_id.get(), get_user_id_object_internal(secret_chat->user_id, "secretChat"),
|
||||
secret_chat_id.get(), get_user_id_object(secret_chat->user_id, "secretChat"),
|
||||
get_secret_chat_state_object(secret_chat->state), secret_chat->is_outbound, secret_chat->ttl,
|
||||
secret_chat->key_hash, secret_chat->layer);
|
||||
}
|
||||
@ -14433,7 +14383,6 @@ td_api::object_ptr<td_api::botInfo> ContactsManager::get_bot_info_object(UserId
|
||||
|
||||
tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_info_object(
|
||||
const string &invite_link) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto it = invite_link_infos_.find(invite_link);
|
||||
if (it == invite_link_infos_.end()) {
|
||||
return nullptr;
|
||||
@ -14467,7 +14416,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
LOG(ERROR) << "Have no information about " << chat_id;
|
||||
}
|
||||
chat_type = td_api::make_object<td_api::chatTypeBasicGroup>(
|
||||
get_basic_group_id_object_internal(chat_id, "get_chat_invite_link_info_object"));
|
||||
get_basic_group_id_object(chat_id, "get_chat_invite_link_info_object"));
|
||||
break;
|
||||
}
|
||||
case DialogType::Channel: {
|
||||
@ -14486,7 +14435,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
LOG(ERROR) << "Have no information about " << channel_id;
|
||||
}
|
||||
chat_type = td_api::make_object<td_api::chatTypeSupergroup>(
|
||||
get_supergroup_id_object_internal(channel_id, "get_chat_invite_link_info_object"), !is_megagroup);
|
||||
get_supergroup_id_object(channel_id, "get_chat_invite_link_info_object"), !is_megagroup);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -14497,7 +14446,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
invite_link_photo = as_fake_dialog_photo(invite_link_info->photo);
|
||||
photo = &invite_link_photo;
|
||||
participant_count = invite_link_info->participant_count;
|
||||
member_user_ids = get_user_ids_object_internal(invite_link_info->participant_user_ids, "get_chat_invite_link_info_object");
|
||||
member_user_ids = get_user_ids_object(invite_link_info->participant_user_ids, "get_chat_invite_link_info_object");
|
||||
is_public = invite_link_info->is_public;
|
||||
|
||||
if (invite_link_info->is_chat) {
|
||||
@ -14524,7 +14473,6 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
}
|
||||
|
||||
UserId ContactsManager::get_support_user(Promise<Unit> &&promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (support_user_id_.is_valid()) {
|
||||
promise.set_value(Unit());
|
||||
return support_user_id_;
|
||||
@ -14535,7 +14483,6 @@ UserId ContactsManager::get_support_user(Promise<Unit> &&promise) {
|
||||
}
|
||||
|
||||
void ContactsManager::after_get_difference() {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
@ -14543,7 +14490,6 @@ void ContactsManager::after_get_difference() {
|
||||
}
|
||||
|
||||
void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
for (auto user_id : unknown_users_) {
|
||||
if (!have_min_user(user_id)) {
|
||||
updates.push_back(get_update_unknown_user_object(user_id));
|
||||
@ -14560,7 +14506,7 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
}
|
||||
}
|
||||
for (auto secret_chat_id : unknown_secret_chats_) {
|
||||
if (!have_secret_chat_internal(secret_chat_id)) {
|
||||
if (!have_secret_chat(secret_chat_id)) {
|
||||
updates.push_back(get_update_unknown_secret_chat_object(secret_chat_id));
|
||||
}
|
||||
}
|
||||
@ -14595,8 +14541,6 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
}
|
||||
|
||||
void ContactsManager::memory_cleanup() {
|
||||
std::lock_guard<std::shared_timed_mutex> writerLock(memory_cleanup_mutex);
|
||||
|
||||
auto time = std::time(nullptr);
|
||||
|
||||
auto user_ttl = !G()->shared_config().get_option_integer("delete_user_reference_after_seconds", 3600);
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -481,14 +480,12 @@ class ContactsManager : public Actor {
|
||||
bool get_channel(ChannelId channel_id, int left_tries, Promise<Unit> &&promise);
|
||||
void reload_channel(ChannelId chnanel_id, Promise<Unit> &&promise);
|
||||
bool load_channel_full(ChannelId channel_id, bool force, Promise<Unit> &&promise);
|
||||
bool load_channel_full_internal(ChannelId channel_id, bool force, Promise<Unit> &&promise);
|
||||
FileSourceId get_channel_full_file_source_id(ChannelId channel_id);
|
||||
void reload_channel_full(ChannelId channel_id, Promise<Unit> &&promise, const char *source);
|
||||
|
||||
bool is_channel_public(ChannelId channel_id) const;
|
||||
|
||||
bool have_secret_chat(SecretChatId secret_chat_id) const;
|
||||
bool have_secret_chat_internal(SecretChatId secret_chat_id) const;
|
||||
bool have_secret_chat_force(SecretChatId secret_chat_id);
|
||||
bool get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise);
|
||||
bool get_secret_chat_full(SecretChatId secret_chat_id, Promise<Unit> &&promise);
|
||||
@ -505,8 +502,6 @@ class ContactsManager : public Actor {
|
||||
|
||||
std::pair<int32, vector<UserId>> search_among_users(const vector<UserId> &user_ids, const string &query, int32 limit);
|
||||
|
||||
std::pair<int32, vector<UserId>> search_among_users_internal(const vector<UserId> &user_ids, const string &query, int32 limit);
|
||||
|
||||
DialogParticipant get_chat_participant(ChatId chat_id, UserId user_id, bool force, Promise<Unit> &&promise);
|
||||
|
||||
std::pair<int32, vector<DialogParticipant>> search_chat_participants(ChatId chat_id, const string &query, int32 limit,
|
||||
@ -531,32 +526,22 @@ class ContactsManager : public Actor {
|
||||
|
||||
int32 get_user_id_object(UserId user_id, const char *source) const;
|
||||
|
||||
int32 get_user_id_object_internal(UserId user_id, const char *source) const;
|
||||
|
||||
tl_object_ptr<td_api::user> get_user_object(UserId user_id) const;
|
||||
|
||||
vector<int32> get_user_ids_object(const vector<UserId> &user_ids, const char *source) const;
|
||||
|
||||
vector<int32> get_user_ids_object_internal(const vector<UserId> &user_ids, const char *source) const;
|
||||
|
||||
tl_object_ptr<td_api::users> get_users_object(int32 total_count, const vector<UserId> &user_ids) const;
|
||||
|
||||
tl_object_ptr<td_api::users> get_users_object_internal(int32 total_count, const vector<UserId> &user_ids) const;
|
||||
|
||||
tl_object_ptr<td_api::userFullInfo> get_user_full_info_object(UserId user_id) const;
|
||||
|
||||
int32 get_basic_group_id_object(ChatId chat_id, const char *source) const;
|
||||
|
||||
int32 get_basic_group_id_object_internal(ChatId chat_id, const char *source) const;
|
||||
|
||||
tl_object_ptr<td_api::basicGroup> get_basic_group_object(ChatId chat_id);
|
||||
|
||||
tl_object_ptr<td_api::basicGroupFullInfo> get_basic_group_full_info_object(ChatId chat_id) const;
|
||||
|
||||
int32 get_supergroup_id_object(ChannelId channel_id, const char *source) const;
|
||||
|
||||
int32 get_supergroup_id_object_internal(ChannelId channel_id, const char *source) const;
|
||||
|
||||
tl_object_ptr<td_api::supergroup> get_supergroup_object(ChannelId channel_id) const;
|
||||
|
||||
tl_object_ptr<td_api::supergroupFullInfo> get_supergroup_full_info_object(ChannelId channel_id) const;
|
||||
@ -1124,10 +1109,8 @@ class ContactsManager : public Actor {
|
||||
Channel *add_channel(ChannelId channel_id, const char *source);
|
||||
|
||||
const ChannelFull *get_channel_full(ChannelId channel_id) const;
|
||||
const ChannelFull *get_channel_full_internal(ChannelId channel_id) const;
|
||||
const ChannelFull *get_channel_full_const(ChannelId channel_id) const;
|
||||
ChannelFull *get_channel_full(ChannelId channel_id, const char *source);
|
||||
ChannelFull *get_channel_full_internal(ChannelId channel_id, const char *source);
|
||||
ChannelFull *get_channel_full_force(ChannelId channel_id, const char *source);
|
||||
|
||||
ChannelFull *add_channel_full(ChannelId channel_id);
|
||||
@ -1627,8 +1610,6 @@ class ContactsManager : public Actor {
|
||||
MultiTimeout user_nearby_timeout_{"UserNearbyTimeout"};
|
||||
MultiTimeout slow_mode_delay_timeout_{"SlowModeDelayTimeout"};
|
||||
MultiTimeout invite_link_info_expire_timeout_{"InviteLinkInfoExpireTimeout"};
|
||||
|
||||
mutable std::shared_timed_mutex memory_cleanup_mutex;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -298,7 +298,7 @@ void FileNode::set_partial_remote_location(const PartialRemoteFileLocation &remo
|
||||
on_changed();
|
||||
}
|
||||
|
||||
bool FileNode::delete_file_reference_internal(Slice file_reference) {
|
||||
bool FileNode::delete_file_reference(Slice file_reference) {
|
||||
if (!remote_.full) {
|
||||
VLOG(file_references) << "Can't delete file reference, because there is no remote location";
|
||||
return false;
|
||||
@ -1034,11 +1034,6 @@ FileManager::FileIdInfo *FileManager::get_file_id_info(FileId file_id) {
|
||||
}
|
||||
|
||||
FileId FileManager::dup_file_id(FileId file_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return dup_file_id_internal(file_id);
|
||||
}
|
||||
|
||||
FileId FileManager::dup_file_id_internal(FileId file_id) {
|
||||
int32 file_node_id;
|
||||
auto *file_node = get_file_node_raw(file_id, &file_node_id);
|
||||
if (!file_node) {
|
||||
@ -1079,7 +1074,7 @@ void FileManager::try_forget_file_id(FileId file_id) {
|
||||
}
|
||||
|
||||
FileId FileManager::register_empty(FileType type) {
|
||||
return register_local_internal(FullLocalFileLocation(type, "", 0), DialogId(), 0, false, true).ok();
|
||||
return register_local(FullLocalFileLocation(type, "", 0), DialogId(), 0, false, true).ok();
|
||||
}
|
||||
|
||||
void FileManager::on_file_unlink(const FullLocalFileLocation &location) {
|
||||
@ -1099,12 +1094,6 @@ void FileManager::on_file_unlink(const FullLocalFileLocation &location) {
|
||||
|
||||
Result<FileId> FileManager::register_local(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
||||
bool get_by_hash, bool force, bool skip_file_size_checks) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return register_local_internal(location, owner_dialog_id, size, get_by_hash, force, skip_file_size_checks);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::register_local_internal(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
||||
bool get_by_hash, bool force, bool skip_file_size_checks) {
|
||||
// TODO: use get_by_hash
|
||||
FileData data;
|
||||
data.local_ = LocalFileLocation(std::move(location));
|
||||
@ -1115,12 +1104,6 @@ Result<FileId> FileManager::register_local_internal(FullLocalFileLocation locati
|
||||
}
|
||||
|
||||
FileId FileManager::register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id, int64 size, int64 expected_size, string remote_name) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return register_remote_internal(location, file_location_source, owner_dialog_id, size, expected_size, std::move(remote_name));
|
||||
}
|
||||
|
||||
FileId FileManager::register_remote_internal(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id, int64 size, int64 expected_size, string remote_name) {
|
||||
FileData data;
|
||||
data.remote_ = RemoteFileLocation(location);
|
||||
@ -1141,7 +1124,7 @@ FileId FileManager::register_remote_internal(const FullRemoteFileLocation &locat
|
||||
|
||||
FileId FileManager::register_url(string url, FileType file_type, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id) {
|
||||
auto file_id = register_generate_internal(file_type, file_location_source, url, "#url#", owner_dialog_id, 0).ok();
|
||||
auto file_id = register_generate(file_type, file_location_source, url, "#url#", owner_dialog_id, 0).ok();
|
||||
auto file_node = get_file_node(file_id);
|
||||
CHECK(file_node);
|
||||
file_node->set_url(url);
|
||||
@ -1151,13 +1134,6 @@ FileId FileManager::register_url(string url, FileType file_type, FileLocationSou
|
||||
Result<FileId> FileManager::register_generate(FileType file_type, FileLocationSource file_location_source,
|
||||
string original_path, string conversion, DialogId owner_dialog_id,
|
||||
int64 expected_size) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return register_generate_internal(file_type, file_location_source, std::move(original_path), std::move(conversion), owner_dialog_id, expected_size);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::register_generate_internal(FileType file_type, FileLocationSource file_location_source,
|
||||
string original_path, string conversion, DialogId owner_dialog_id,
|
||||
int64 expected_size) {
|
||||
// add #mtime# into conversion
|
||||
if (!original_path.empty() && conversion[0] != '#' && PathView(original_path).is_absolute()) {
|
||||
auto file_paths = log_interface->get_file_paths();
|
||||
@ -1273,7 +1249,7 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
|
||||
bool no_sync_merge = to_merge.size() == 1 && new_cnt == 0;
|
||||
for (auto id : to_merge) {
|
||||
// may invalidate node
|
||||
merge_internal(file_id, id, no_sync_merge).ignore();
|
||||
merge(file_id, id, no_sync_merge).ignore();
|
||||
}
|
||||
|
||||
try_flush_node(get_file_node(file_id), "register_file");
|
||||
@ -1447,11 +1423,6 @@ void FileManager::do_cancel_generate(FileNodePtr node) {
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sync) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return merge_internal(x_file_id, y_file_id, no_sync);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::merge_internal(FileId x_file_id, FileId y_file_id, bool no_sync) {
|
||||
LOG(DEBUG) << "Merge new file " << x_file_id << " and old file " << y_file_id;
|
||||
|
||||
if (!x_file_id.is_valid()) {
|
||||
@ -1711,11 +1682,6 @@ Result<FileId> FileManager::merge_internal(FileId x_file_id, FileId y_file_id, b
|
||||
}
|
||||
|
||||
void FileManager::add_file_source(FileId file_id, FileSourceId file_source_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return add_file_source_internal(file_id, file_source_id);
|
||||
}
|
||||
|
||||
void FileManager::add_file_source_internal(FileId file_id, FileSourceId file_source_id) {
|
||||
auto node = get_file_node(file_id);
|
||||
if (!node) {
|
||||
return;
|
||||
@ -1743,7 +1709,6 @@ void FileManager::remove_file_source(FileId file_id, FileSourceId file_source_id
|
||||
|
||||
void FileManager::change_files_source(FileSourceId file_source_id, const vector<FileId> &old_file_ids,
|
||||
const vector<FileId> &new_file_ids) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (old_file_ids == new_file_ids) {
|
||||
return;
|
||||
}
|
||||
@ -1760,7 +1725,7 @@ void FileManager::change_files_source(FileSourceId file_source_id, const vector<
|
||||
}
|
||||
}
|
||||
for (auto file_id : new_main_file_ids) {
|
||||
add_file_source_internal(file_id, file_source_id);
|
||||
add_file_source(file_id, file_source_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1973,7 +1938,7 @@ void FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_loca
|
||||
TRY_RESULT(file_data, file_db_->get_file_data_sync(location));
|
||||
TRY_RESULT(new_file_id,
|
||||
register_file(std::move(file_data), FileLocationSource::FromDatabase, "load_from_pmc", false));
|
||||
TRY_RESULT(main_file_id, merge_internal(file_id, new_file_id));
|
||||
TRY_RESULT(main_file_id, merge(file_id, new_file_id));
|
||||
file_id = main_file_id;
|
||||
return Status::OK();
|
||||
};
|
||||
@ -2006,7 +1971,6 @@ bool FileManager::set_encryption_key(FileId file_id, FileEncryptionKey key) {
|
||||
}
|
||||
|
||||
bool FileManager::set_content(FileId file_id, BufferSlice bytes) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (G()->shared_config().get_option_boolean("ignore_inline_thumbnails")) {
|
||||
return false;
|
||||
}
|
||||
@ -2041,7 +2005,6 @@ bool FileManager::set_content(FileId file_id, BufferSlice bytes) {
|
||||
}
|
||||
|
||||
void FileManager::get_content(FileId file_id, Promise<BufferSlice> promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto node = get_sync_file_node(file_id);
|
||||
if (!node) {
|
||||
return promise.set_error(Status::Error("Unknown file_id"));
|
||||
@ -2059,7 +2022,6 @@ void FileManager::get_content(FileId file_id, Promise<BufferSlice> promise) {
|
||||
|
||||
void FileManager::read_file_part(FileId file_id, int32 offset, int32 count, int left_tries,
|
||||
Promise<td_api::object_ptr<td_api::filePart>> promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (G()->close_flag()) {
|
||||
return promise.set_error(Status::Error(500, "Request aborted"));
|
||||
}
|
||||
@ -2138,7 +2100,6 @@ void FileManager::read_file_part(FileId file_id, int32 offset, int32 count, int
|
||||
}
|
||||
|
||||
void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char *source) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
LOG(INFO) << "Trying to delete file " << file_id << " from " << source;
|
||||
auto node = get_sync_file_node(file_id);
|
||||
if (!node) {
|
||||
@ -2175,7 +2136,6 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
|
||||
|
||||
void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
|
||||
int64 limit) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
LOG(INFO) << "Download file " << file_id << " with priority " << new_priority;
|
||||
auto node = get_sync_file_node(file_id);
|
||||
if (!node) {
|
||||
@ -2588,7 +2548,6 @@ void FileManager::resume_upload(FileId file_id, std::vector<int> bad_parts, std:
|
||||
}
|
||||
|
||||
bool FileManager::delete_partial_remote_location(FileId file_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto node = get_sync_file_node(file_id);
|
||||
if (!node) {
|
||||
LOG(INFO) << "Wrong file identifier " << file_id;
|
||||
@ -2623,11 +2582,6 @@ bool FileManager::delete_partial_remote_location(FileId file_id) {
|
||||
}
|
||||
|
||||
void FileManager::delete_file_reference(FileId file_id, string file_reference) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return delete_file_reference_internal(file_id, file_reference);
|
||||
}
|
||||
|
||||
void FileManager::delete_file_reference_internal(FileId file_id, string file_reference) {
|
||||
VLOG(file_references) << "Delete file reference of file " << file_id << " "
|
||||
<< tag("reference_base64", base64_encode(file_reference));
|
||||
auto node = get_sync_file_node(file_id);
|
||||
@ -2635,7 +2589,7 @@ void FileManager::delete_file_reference_internal(FileId file_id, string file_ref
|
||||
LOG(ERROR) << "Wrong file identifier " << file_id;
|
||||
return;
|
||||
}
|
||||
node->delete_file_reference_internal(file_reference);
|
||||
node->delete_file_reference(file_reference);
|
||||
auto remote = get_remote(file_id.get_remote());
|
||||
if (remote != nullptr) {
|
||||
VLOG(file_references) << "Do delete file reference of remote file " << file_id;
|
||||
@ -2650,20 +2604,17 @@ void FileManager::delete_file_reference_internal(FileId file_id, string file_ref
|
||||
}
|
||||
|
||||
void FileManager::external_file_generate_write_part(int64 id, int32 offset, string data, Promise<> promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
send_closure(file_generate_manager_, &FileGenerateManager::external_file_generate_write_part, id, offset,
|
||||
std::move(data), std::move(promise));
|
||||
}
|
||||
|
||||
void FileManager::external_file_generate_progress(int64 id, int32 expected_size, int32 local_prefix_size,
|
||||
Promise<> promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
send_closure(file_generate_manager_, &FileGenerateManager::external_file_generate_progress, id, expected_size,
|
||||
local_prefix_size, std::move(promise));
|
||||
}
|
||||
|
||||
void FileManager::external_file_generate_finish(int64 id, Status status, Promise<> promise) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
send_closure(file_generate_manager_, &FileGenerateManager::external_file_generate_finish, id, std::move(status),
|
||||
std::move(promise));
|
||||
}
|
||||
@ -2865,12 +2816,10 @@ void FileManager::run_upload(FileNodePtr node, std::vector<int> bad_parts) {
|
||||
|
||||
void FileManager::upload(FileId file_id, std::shared_ptr<UploadCallback> callback, int32 new_priority,
|
||||
uint64 upload_order) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return resume_upload(file_id, std::vector<int>(), std::move(callback), new_priority, upload_order);
|
||||
}
|
||||
|
||||
void FileManager::cancel_upload(FileId file_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
return resume_upload(file_id, std::vector<int>(), nullptr, 0, 0);
|
||||
}
|
||||
|
||||
@ -2995,7 +2944,6 @@ FileView FileManager::get_sync_file_view(FileId file_id) {
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool with_main_file_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto file_view = get_sync_file_view(file_id);
|
||||
|
||||
if (file_view.empty()) {
|
||||
@ -3039,7 +2987,6 @@ td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bo
|
||||
|
||||
vector<int32> FileManager::get_file_ids_object(const vector<FileId> &file_ids, bool with_main_file_id) {
|
||||
return transform(file_ids, [this, with_main_file_id](FileId file_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
auto file_view = get_sync_file_view(file_id);
|
||||
auto result_file_id = file_id;
|
||||
auto *file_info = get_file_id_info(result_file_id);
|
||||
@ -3081,7 +3028,7 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
|
||||
if (!file_view.has_remote_location()) {
|
||||
// TODO why not return file_id here? We will dup it anyway
|
||||
// But it will not be duped if has_input_media(), so for now we can't return main_file_id
|
||||
return dup_file_id_internal(file_id);
|
||||
return dup_file_id(file_id);
|
||||
}
|
||||
|
||||
int32 remote_id = file_id.get_remote();
|
||||
@ -3098,7 +3045,6 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
|
||||
|
||||
Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_api::InputFile> &thumbnail_input_file,
|
||||
DialogId owner_dialog_id, bool is_encrypted) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (thumbnail_input_file == nullptr) {
|
||||
return Status::Error(6, "inputThumbnail not specified");
|
||||
}
|
||||
@ -3106,7 +3052,7 @@ Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_a
|
||||
switch (thumbnail_input_file->get_id()) {
|
||||
case td_api::inputFileLocal::ID: {
|
||||
const string &path = static_cast<const td_api::inputFileLocal *>(thumbnail_input_file.get())->path_;
|
||||
return register_local_internal(
|
||||
return register_local(
|
||||
FullLocalFileLocation(is_encrypted ? FileType::EncryptedThumbnail : FileType::Thumbnail, path, 0),
|
||||
owner_dialog_id, 0, false);
|
||||
}
|
||||
@ -3116,7 +3062,7 @@ Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_a
|
||||
return Status::Error(6, "InputFileRemote is not supported for thumbnails");
|
||||
case td_api::inputFileGenerated::ID: {
|
||||
auto *generated_thumbnail = static_cast<const td_api::inputFileGenerated *>(thumbnail_input_file.get());
|
||||
return register_generate_internal(is_encrypted ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
||||
return register_generate(is_encrypted ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
||||
FileLocationSource::FromUser, generated_thumbnail->original_path_,
|
||||
generated_thumbnail->conversion_, owner_dialog_id, generated_thumbnail->expected_size_);
|
||||
}
|
||||
@ -3129,7 +3075,6 @@ Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_a
|
||||
Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr<td_api::InputFile> &file,
|
||||
DialogId owner_dialog_id, bool allow_zero, bool is_encrypted,
|
||||
bool get_by_hash, bool is_secure) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (file == nullptr) {
|
||||
if (allow_zero) {
|
||||
return FileId();
|
||||
@ -3167,7 +3112,7 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
||||
}
|
||||
}
|
||||
}
|
||||
TRY_RESULT(file_id, register_local_internal(FullLocalFileLocation(new_type, path, 0), owner_dialog_id, 0, get_by_hash));
|
||||
TRY_RESULT(file_id, register_local(FullLocalFileLocation(new_type, path, 0), owner_dialog_id, 0, get_by_hash));
|
||||
if (!hash.empty()) {
|
||||
file_hash_to_file_id_[hash] = file_id;
|
||||
}
|
||||
@ -3189,7 +3134,7 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
||||
}
|
||||
case td_api::inputFileGenerated::ID: {
|
||||
auto *generated_file = static_cast<const td_api::inputFileGenerated *>(file.get());
|
||||
return register_generate_internal(new_type, FileLocationSource::FromUser, generated_file->original_path_,
|
||||
return register_generate(new_type, FileLocationSource::FromUser, generated_file->original_path_,
|
||||
generated_file->conversion_, owner_dialog_id, generated_file->expected_size_);
|
||||
}
|
||||
default:
|
||||
@ -3203,7 +3148,6 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
||||
|
||||
Result<FileId> FileManager::get_map_thumbnail_file_id(Location location, int32 zoom, int32 width, int32 height,
|
||||
int32 scale, DialogId owner_dialog_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
if (!location.is_valid_map_point()) {
|
||||
return Status::Error(6, "Invalid location specified");
|
||||
}
|
||||
@ -3230,13 +3174,12 @@ Result<FileId> FileManager::get_map_thumbnail_file_id(Location location, int32 z
|
||||
|
||||
string conversion = PSTRING() << "#map#" << zoom << "#" << x << "#" << y << "#" << width << "#" << height << "#"
|
||||
<< scale << "#";
|
||||
return register_generate_internal(
|
||||
return register_generate(
|
||||
owner_dialog_id.get_type() == DialogType::SecretChat ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
||||
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);
|
||||
}
|
||||
|
||||
vector<tl_object_ptr<telegram_api::InputDocument>> FileManager::get_input_documents(const vector<FileId> &file_ids) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
vector<tl_object_ptr<telegram_api::InputDocument>> result;
|
||||
result.reserve(file_ids.size());
|
||||
for (auto file_id : file_ids) {
|
||||
@ -3268,7 +3211,6 @@ bool FileManager::extract_was_thumbnail_uploaded(const tl_object_ptr<telegram_ap
|
||||
}
|
||||
|
||||
string FileManager::extract_file_reference(const tl_object_ptr<telegram_api::InputMedia> &input_media) {
|
||||
// don't lock this method because now it only calls the other extract_file_reference
|
||||
if (input_media == nullptr) {
|
||||
return string();
|
||||
}
|
||||
@ -3304,7 +3246,6 @@ bool FileManager::extract_was_uploaded(const tl_object_ptr<telegram_api::InputCh
|
||||
}
|
||||
|
||||
string FileManager::extract_file_reference(const tl_object_ptr<telegram_api::InputChatPhoto> &input_chat_photo) {
|
||||
// don't lock this method because now it only calls the other extract_file_reference
|
||||
if (input_chat_photo == nullptr || input_chat_photo->get_id() != telegram_api::inputChatPhoto::ID) {
|
||||
return string();
|
||||
}
|
||||
@ -3328,8 +3269,6 @@ FileManager::FileNodeId FileManager::next_file_node_id() {
|
||||
}
|
||||
|
||||
void FileManager::on_start_download(QueryId query_id) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
|
||||
if (is_closed_) {
|
||||
return;
|
||||
}
|
||||
@ -3355,8 +3294,6 @@ void FileManager::on_start_download(QueryId query_id) {
|
||||
|
||||
void FileManager::on_partial_download(QueryId query_id, const PartialLocalFileLocation &partial_local, int64 ready_size,
|
||||
int64 size) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
|
||||
if (is_closed_) {
|
||||
return;
|
||||
}
|
||||
@ -3388,8 +3325,6 @@ void FileManager::on_partial_download(QueryId query_id, const PartialLocalFileLo
|
||||
}
|
||||
|
||||
void FileManager::on_hash(QueryId query_id, string hash) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
|
||||
if (is_closed_) {
|
||||
return;
|
||||
}
|
||||
@ -3415,8 +3350,6 @@ void FileManager::on_hash(QueryId query_id, string hash) {
|
||||
|
||||
void FileManager::on_partial_upload(QueryId query_id, const PartialRemoteFileLocation &partial_remote,
|
||||
int64 ready_size) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
|
||||
if (is_closed_) {
|
||||
return;
|
||||
}
|
||||
@ -3441,8 +3374,6 @@ void FileManager::on_partial_upload(QueryId query_id, const PartialRemoteFileLoc
|
||||
}
|
||||
|
||||
void FileManager::on_download_ok(QueryId query_id, const FullLocalFileLocation &local, int64 size, bool is_new) {
|
||||
std::shared_lock<std::shared_timed_mutex> readerLock(memory_cleanup_mutex);
|
||||
|
||||
if (is_closed_) {
|
||||
return;
|
||||
}
|
||||
@ -3452,7 +3383,7 @@ void FileManager::on_download_ok(QueryId query_id, const FullLocalFileLocation &
|
||||
std::tie(query, was_active) = finish_query(query_id);
|
||||
auto file_id = query.file_id_;
|
||||
LOG(INFO) << "ON DOWNLOAD OK of " << (is_new ? "new" : "checked") << " file " << file_id << " of size " << size;
|
||||
auto r_new_file_id = register_local_internal(local, DialogId(), size, false, false, true);
|
||||
auto r_new_file_id = register_local(local, DialogId(), size, false, false, true);
|
||||
Status status = Status::OK();
|
||||
if (r_new_file_id.is_error()) {
|
||||
status = Status::Error(PSLICE() << "Can't register local file after download: " << r_new_file_id.error().message());
|
||||
@ -3460,7 +3391,7 @@ void FileManager::on_download_ok(QueryId query_id, const FullLocalFileLocation &
|
||||
if (is_new) {
|
||||
context_->on_new_file(size, get_file_view(r_new_file_id.ok()).get_allocated_local_size(), 1);
|
||||
}
|
||||
auto r_file_id = merge_internal(r_new_file_id.ok(), file_id);
|
||||
auto r_file_id = merge(r_new_file_id.ok(), file_id);
|
||||
if (r_file_id.is_error()) {
|
||||
status = r_file_id.move_as_error();
|
||||
}
|
||||
@ -3555,8 +3486,8 @@ void FileManager::on_upload_full_ok(QueryId query_id, const FullRemoteFileLocati
|
||||
|
||||
auto file_id = finish_query(query_id).first.file_id_;
|
||||
LOG(INFO) << "ON UPLOAD FULL OK for file " << file_id;
|
||||
auto new_file_id = register_remote_internal(remote, FileLocationSource::FromServer, DialogId(), 0, 0, "");
|
||||
LOG_STATUS(merge_internal(new_file_id, file_id));
|
||||
auto new_file_id = register_remote(remote, FileLocationSource::FromServer, DialogId(), 0, 0, "");
|
||||
LOG_STATUS(merge(new_file_id, file_id));
|
||||
}
|
||||
|
||||
void FileManager::on_partial_generate(QueryId query_id, const PartialLocalFileLocation &partial_local,
|
||||
@ -3616,12 +3547,12 @@ void FileManager::on_generate_ok(QueryId query_id, const FullLocalFileLocation &
|
||||
|
||||
auto old_upload_id = file_node->upload_id_;
|
||||
|
||||
auto r_new_file_id = register_local_internal(local, DialogId(), 0);
|
||||
auto r_new_file_id = register_local(local, DialogId(), 0);
|
||||
Status status;
|
||||
if (r_new_file_id.is_error()) {
|
||||
status = Status::Error(PSLICE() << "Can't register local file after generate: " << r_new_file_id.error());
|
||||
} else {
|
||||
auto result = merge_internal(r_new_file_id.ok(), generate_file_id);
|
||||
auto result = merge(r_new_file_id.ok(), generate_file_id);
|
||||
if (result.is_error()) {
|
||||
status = result.move_as_error();
|
||||
}
|
||||
@ -3740,7 +3671,7 @@ void FileManager::on_error_impl(FileNodePtr node, Query::Type type, bool was_act
|
||||
LOG(ERROR) << "Unexpected error, file_reference will be deleted just in case " << status;
|
||||
}
|
||||
CHECK(!node->file_ids_.empty());
|
||||
delete_file_reference_internal(node->file_ids_.back(), file_reference);
|
||||
delete_file_reference(node->file_ids_.back(), file_reference);
|
||||
run_download(node, true);
|
||||
return;
|
||||
}
|
||||
@ -3864,8 +3795,6 @@ void FileManager::destroy_query(int32 file_id) {
|
||||
|
||||
|
||||
void FileManager::memory_cleanup() {
|
||||
std::lock_guard<std::shared_timed_mutex> writerLock(memory_cleanup_mutex);
|
||||
|
||||
LOG(ERROR) << "Initial registered ids: " << file_id_info_.size() << " registered nodes: " << file_nodes_.size();
|
||||
|
||||
std::unordered_set<int32> file_to_be_deleted = {};
|
||||
|
@ -41,7 +41,6 @@
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -95,7 +94,6 @@ class FileNode {
|
||||
void set_partial_remote_location(const PartialRemoteFileLocation &remote, int64 ready_size);
|
||||
|
||||
bool delete_file_reference(Slice file_reference);
|
||||
bool delete_file_reference_internal(Slice file_reference);
|
||||
void set_generate_location(unique_ptr<FullGenerateFileLocation> &&generate);
|
||||
void set_size(int64 size);
|
||||
void set_expected_size(int64 expected_size);
|
||||
@ -424,38 +422,23 @@ class FileManager : public FileLoadManager::Callback {
|
||||
|
||||
FileId dup_file_id(FileId file_id);
|
||||
|
||||
FileId dup_file_id_internal(FileId file_id);
|
||||
|
||||
void on_file_unlink(const FullLocalFileLocation &location);
|
||||
|
||||
FileId register_empty(FileType type);
|
||||
Result<FileId> register_local(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
||||
bool get_by_hash = false, bool force = false,
|
||||
bool skip_file_size_checks = false) TD_WARN_UNUSED_RESULT;
|
||||
Result<FileId> register_local_internal(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
||||
bool get_by_hash = false, bool force = false,
|
||||
bool skip_file_size_checks = false) TD_WARN_UNUSED_RESULT;
|
||||
FileId register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id, int64 size, int64 expected_size,
|
||||
string remote_name) TD_WARN_UNUSED_RESULT;
|
||||
FileId register_remote_internal(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||
DialogId owner_dialog_id, int64 size, int64 expected_size,
|
||||
string remote_name) TD_WARN_UNUSED_RESULT;
|
||||
Result<FileId> register_generate(FileType file_type, FileLocationSource file_location_source, string original_path,
|
||||
string conversion, DialogId owner_dialog_id,
|
||||
int64 expected_size) TD_WARN_UNUSED_RESULT;
|
||||
Result<FileId> register_generate_internal(FileType file_type, FileLocationSource file_location_source, string original_path,
|
||||
string conversion, DialogId owner_dialog_id,
|
||||
int64 expected_size) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Result<FileId> merge(FileId x_file_id, FileId y_file_id, bool no_sync = false) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Result<FileId> merge_internal(FileId x_file_id, FileId y_file_id, bool no_sync = false) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
void add_file_source(FileId file_id, FileSourceId file_source_id);
|
||||
|
||||
void add_file_source_internal(FileId file_id, FileSourceId file_source_id);
|
||||
|
||||
void remove_file_source(FileId file_id, FileSourceId file_source_id);
|
||||
|
||||
void change_files_source(FileSourceId file_source_id, const vector<FileId> &old_file_ids,
|
||||
@ -475,7 +458,6 @@ class FileManager : public FileLoadManager::Callback {
|
||||
void cancel_upload(FileId file_id);
|
||||
bool delete_partial_remote_location(FileId file_id);
|
||||
void delete_file_reference(FileId file_id, std::string file_reference);
|
||||
void delete_file_reference_internal(FileId file_id, std::string file_reference);
|
||||
void get_content(FileId file_id, Promise<BufferSlice> promise);
|
||||
|
||||
void read_file_part(FileId file_id, int32 offset, int32 count, int left_tries,
|
||||
@ -689,8 +671,6 @@ class FileManager : public FileLoadManager::Callback {
|
||||
void hangup() override;
|
||||
void tear_down() override;
|
||||
|
||||
mutable std::shared_timed_mutex memory_cleanup_mutex;
|
||||
|
||||
friend class FileNodePtr;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user