From f2e549e3614598f6b742f107d7331dada6a69a0b Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 3 May 2020 15:44:33 +0300 Subject: [PATCH] Do not dup remotely available files for bots to fix bad FileManager performance. GitOrigin-RevId: adbd9e3fdfdf249572472bcbccfea030c75a6992 --- td/telegram/DocumentsManager.cpp | 4 ++++ td/telegram/MessageContent.cpp | 2 +- td/telegram/Photo.cpp | 5 ++++- td/telegram/Photo.h | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/td/telegram/DocumentsManager.cpp b/td/telegram/DocumentsManager.cpp index 87edd124..f181043c 100644 --- a/td/telegram/DocumentsManager.cpp +++ b/td/telegram/DocumentsManager.cpp @@ -8,6 +8,7 @@ #include "td/telegram/AnimationsManager.h" #include "td/telegram/AudiosManager.h" +#include "td/telegram/AuthManager.h" #include "td/telegram/Document.h" #include "td/telegram/files/FileEncryptionKey.h" #include "td/telegram/files/FileLocation.h" @@ -505,6 +506,9 @@ bool DocumentsManager::has_input_media(FileId file_id, FileId thumbnail_file_id, if (file_view.is_encrypted()) { return false; } + if (td_->auth_manager_->is_bot() && file_view.has_remote_location()) { + return true; + } // having remote location is not enough to have InputMedia, because the file may not have valid file_reference // also file_id needs to be duped, because upload can be called to repair the file_reference and every upload // request must have unique file_id diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 46aa733e..9208bbdb 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4039,7 +4039,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const photo.type = 'i'; result->photo.photos.push_back(std::move(photo)); - if (photo_has_input_media(td->file_manager_.get(), result->photo, to_secret)) { + if (photo_has_input_media(td->file_manager_.get(), result->photo, to_secret, td->auth_manager_->is_bot())) { return std::move(result); } diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 3f7c6eda..6a5dc6d1 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -591,7 +591,7 @@ void photo_delete_thumbnail(Photo &photo) { } } -bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret) { +bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret, bool is_bot) { if (photo.photos.empty() || photo.photos.back().type != 'i') { LOG(ERROR) << "Wrong photo: " << photo; return false; @@ -614,6 +614,9 @@ bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool i if (file_view.is_encrypted()) { return false; } + if (is_bot && file_view.has_remote_location()) { + return true; + } return /* file_view.has_remote_location() || */ file_view.has_url(); } } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 23cee3b8..f4c66a1d 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -120,7 +120,7 @@ tl_object_ptr get_user_profile_photo_object(FileManage void photo_delete_thumbnail(Photo &photo); -bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret); +bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret, bool is_bot); SecretInputMedia photo_get_secret_input_media(FileManager *file_manager, const Photo &photo, tl_object_ptr input_file,