Don't keep exact remote location for bots.
This commit is contained in:
parent
6f94c363f7
commit
de22159b7f
|
@ -3809,6 +3809,10 @@ void Td::init_file_manager() {
|
|||
FileReferenceManager::reload_photo(std::move(source), std::move(promise));
|
||||
}
|
||||
|
||||
bool keep_exact_remote_location() final {
|
||||
return !td_->auth_manager_->is_bot();
|
||||
}
|
||||
|
||||
ActorShared<> create_reference() final {
|
||||
return td_->create_reference();
|
||||
}
|
||||
|
|
|
@ -841,8 +841,9 @@ void FileManager::init_actor() {
|
|||
|
||||
FileManager::~FileManager() {
|
||||
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), remote_location_info_, file_hash_to_file_id_,
|
||||
local_location_to_file_id_, generate_location_to_file_id_,
|
||||
pmc_id_to_file_node_id_, file_id_info_, empty_file_ids_, file_nodes_);
|
||||
remote_location_to_file_id_, local_location_to_file_id_,
|
||||
generate_location_to_file_id_, pmc_id_to_file_node_id_, file_id_info_,
|
||||
empty_file_ids_, file_nodes_);
|
||||
}
|
||||
|
||||
string FileManager::fix_file_extension(Slice file_name, Slice file_type, Slice file_extension) {
|
||||
|
@ -1300,8 +1301,10 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
|
|||
}
|
||||
};
|
||||
bool new_remote = false;
|
||||
FileId *new_remote_file_id = nullptr;
|
||||
int32 remote_key = 0;
|
||||
if (file_view.has_remote_location()) {
|
||||
if (context_->keep_exact_remote_location()) {
|
||||
RemoteInfo info{file_view.remote_location(), file_location_source, file_id};
|
||||
remote_key = remote_location_info_.add(info);
|
||||
auto &stored_info = remote_location_info_.get(remote_key);
|
||||
|
@ -1316,6 +1319,10 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
|
|||
stored_info.file_location_source_ = file_location_source;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
new_remote_file_id = register_location(file_view.remote_location(), remote_location_to_file_id_);
|
||||
new_remote = new_remote_file_id != nullptr;
|
||||
}
|
||||
}
|
||||
FileId *new_local_file_id = nullptr;
|
||||
if (file_view.has_local_location()) {
|
||||
|
@ -1344,6 +1351,9 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
|
|||
try_flush_node(get_file_node(file_id), "register_file");
|
||||
auto main_file_id = get_file_node(file_id)->main_file_id_;
|
||||
if (main_file_id != file_id) {
|
||||
if (new_remote_file_id != nullptr) {
|
||||
*new_remote_file_id = main_file_id;
|
||||
}
|
||||
if (new_local_file_id != nullptr) {
|
||||
*new_local_file_id = main_file_id;
|
||||
}
|
||||
|
@ -1352,7 +1362,7 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
|
|||
}
|
||||
try_forget_file_id(file_id);
|
||||
}
|
||||
if ((new_local_file_id != nullptr) || (new_generate_file_id != nullptr)) {
|
||||
if (new_cnt > 0) {
|
||||
get_file_id_info(main_file_id)->pin_flag_ = true;
|
||||
}
|
||||
|
||||
|
@ -3221,7 +3231,7 @@ Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> re
|
|||
}
|
||||
|
||||
int32 remote_id = file_id.get_remote();
|
||||
if (remote_id == 0) {
|
||||
if (remote_id == 0 && context_->keep_exact_remote_location()) {
|
||||
RemoteInfo info{file_view.remote_location(), FileLocationSource::FromUser, file_id};
|
||||
remote_id = remote_location_info_.add(info);
|
||||
if (remote_location_info_.get(remote_id).file_id_ == file_id) {
|
||||
|
@ -4062,7 +4072,7 @@ std::pair<FileManager::Query, bool> FileManager::finish_query(QueryId query_id)
|
|||
}
|
||||
|
||||
FullRemoteFileLocation *FileManager::get_remote(int32 key) {
|
||||
if (key == 0) {
|
||||
if (key == 0 || !context_->keep_exact_remote_location()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &remote_location_info_.get(key).remote_;
|
||||
|
|
|
@ -402,6 +402,8 @@ class FileManager final : public FileLoadManager::Callback {
|
|||
|
||||
virtual void reload_photo(PhotoSizeSource source, Promise<Unit> promise) = 0;
|
||||
|
||||
virtual bool keep_exact_remote_location() = 0;
|
||||
|
||||
virtual ActorShared<> create_reference() = 0;
|
||||
|
||||
Context() = default;
|
||||
|
@ -587,6 +589,7 @@ class FileManager final : public FileLoadManager::Callback {
|
|||
|
||||
WaitFreeHashMap<string, FileId> file_hash_to_file_id_;
|
||||
|
||||
std::map<FullRemoteFileLocation, FileId> remote_location_to_file_id_;
|
||||
std::map<FullLocalFileLocation, FileId> local_location_to_file_id_;
|
||||
std::map<FullGenerateFileLocation, FileId> generate_location_to_file_id_;
|
||||
std::map<FileDbId, int32> pmc_id_to_file_node_id_;
|
||||
|
|
Loading…
Reference in New Issue
Block a user