Do not dup remotely available files for bots to fix bad FileManager performance.

GitOrigin-RevId: adbd9e3fdfdf249572472bcbccfea030c75a6992
This commit is contained in:
levlam 2020-05-03 15:44:33 +03:00
parent 8826f2690d
commit f2e549e361
4 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -4039,7 +4039,7 @@ unique_ptr<MessageContent> 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);
}

View File

@ -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();
}
}

View File

@ -120,7 +120,7 @@ tl_object_ptr<td_api::userProfilePhoto> 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<telegram_api::InputEncryptedFile> input_file,