From 0971292303700331e7cbdccd515539c4709c3b26 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 16 Jul 2024 13:58:48 +0300 Subject: [PATCH] Remove update_downloaded_part from FileLoaderActor. --- td/telegram/files/FileDownloadManager.cpp | 19 +++++++++++-------- td/telegram/files/FileDownloadManager.h | 3 ++- td/telegram/files/FileDownloader.h | 4 ++-- td/telegram/files/FileLoaderActor.h | 4 ---- td/telegram/files/FileUploader.h | 15 ++++++--------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/td/telegram/files/FileDownloadManager.cpp b/td/telegram/files/FileDownloadManager.cpp index 31965abe0..8a52800b8 100644 --- a/td/telegram/files/FileDownloadManager.cpp +++ b/td/telegram/files/FileDownloadManager.cpp @@ -54,13 +54,13 @@ void FileDownloadManager::download(QueryId query_id, const FullRemoteFileLocatio node->query_id_ = query_id; auto callback = make_unique(actor_shared(this, node_id)); bool is_small = size < 20 * 1024; - node->loader_ = + node->downloader_ = create_actor("Downloader", remote_location, local, size, std::move(name), encryption_key, is_small, need_search_file, offset, limit, std::move(callback)); DcId dc_id = remote_location.is_web() ? G()->get_webfile_dc_id() : remote_location.get_dc_id(); auto &resource_manager = get_download_resource_manager(is_small, dc_id); send_closure(resource_manager, &ResourceManager::register_worker, - ActorShared(node->loader_.get(), static_cast(-1)), priority); + ActorShared(node->downloader_.get(), static_cast(-1)), priority); bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; CHECK(is_inserted); } @@ -74,10 +74,10 @@ void FileDownloadManager::update_priority(QueryId query_id, int8 priority) { return; } auto node = nodes_container_.get(it->second); - if (node == nullptr) { + if (node == nullptr || node->downloader_.empty()) { return; } - send_closure(node->loader_, &FileLoaderActor::update_priority, priority); + send_closure(node->downloader_, &FileLoaderActor::update_priority, priority); } void FileDownloadManager::from_bytes(QueryId query_id, FileType type, BufferSlice bytes, string name) { @@ -89,7 +89,7 @@ void FileDownloadManager::from_bytes(QueryId query_id, FileType type, BufferSlic CHECK(node); node->query_id_ = query_id; auto callback = make_unique(actor_shared(this, node_id)); - node->loader_ = + node->from_bytes_ = create_actor("FromBytes", type, std::move(bytes), std::move(name), std::move(callback)); bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; CHECK(is_inserted); @@ -115,14 +115,17 @@ void FileDownloadManager::update_downloaded_part(QueryId query_id, int64 offset, return; } auto node = nodes_container_.get(it->second); - if (node == nullptr) { + if (node == nullptr || node->downloader_.empty()) { return; } - send_closure(node->loader_, &FileLoaderActor::update_downloaded_part, offset, limit, max_download_resource_limit_); + send_closure(node->downloader_, &FileDownloader::update_downloaded_part, offset, limit, max_download_resource_limit_); } void FileDownloadManager::hangup() { - nodes_container_.for_each([](auto query_id, auto &node) { node.loader_.reset(); }); + nodes_container_.for_each([](auto query_id, auto &node) { + node.downloader_.reset(); + node.from_bytes_.reset(); + }); stop_flag_ = true; loop(); } diff --git a/td/telegram/files/FileDownloadManager.h b/td/telegram/files/FileDownloadManager.h index 63fd8dc2d..8059e60ec 100644 --- a/td/telegram/files/FileDownloadManager.h +++ b/td/telegram/files/FileDownloadManager.h @@ -56,7 +56,8 @@ class FileDownloadManager final : public Actor { private: struct Node { QueryId query_id_; - ActorOwn loader_; + ActorOwn downloader_; + ActorOwn from_bytes_; }; using NodeId = uint64; diff --git a/td/telegram/files/FileDownloader.h b/td/telegram/files/FileDownloader.h index 62ee6419b..73ef72059 100644 --- a/td/telegram/files/FileDownloader.h +++ b/td/telegram/files/FileDownloader.h @@ -48,6 +48,8 @@ class FileDownloader final : public FileLoaderActor { const FileEncryptionKey &encryption_key, bool is_small, bool need_search_file, int64 offset, int64 limit, unique_ptr callback); + void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit); + // Should just implement all parent pure virtual methods. // Must not call any of them... private: @@ -137,8 +139,6 @@ class FileDownloader final : public FileLoaderActor { void update_resources(const ResourceState &other) final; - void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) final; - void start_up() final; void loop() final; Status do_loop(); diff --git a/td/telegram/files/FileLoaderActor.h b/td/telegram/files/FileLoaderActor.h index 898a7ed13..44d357dda 100644 --- a/td/telegram/files/FileLoaderActor.h +++ b/td/telegram/files/FileLoaderActor.h @@ -21,10 +21,6 @@ class FileLoaderActor : public NetQueryCallback { virtual void set_resource_manager(ActorShared resource_manager) = 0; virtual void update_priority(int8 priority) = 0; virtual void update_resources(const ResourceState &other) = 0; - - // TODO: existence of these two functions is a dirty hack. Refactoring is highly appreciated - virtual void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { - } }; } // namespace td diff --git a/td/telegram/files/FileUploader.h b/td/telegram/files/FileUploader.h index 97e2ae8aa..a951e7042 100644 --- a/td/telegram/files/FileUploader.h +++ b/td/telegram/files/FileUploader.h @@ -42,17 +42,8 @@ class FileUploader final : public FileLoaderActor { FileUploader(const LocalFileLocation &local, const RemoteFileLocation &remote, int64 expected_size, const FileEncryptionKey &encryption_key, std::vector bad_parts, unique_ptr callback); - void set_resource_manager(ActorShared resource_manager) final; - - void update_priority(int8 priority) final; - - void update_resources(const ResourceState &other) final; - void update_local_file_location(const LocalFileLocation &local); - void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { - } - private: LocalFileLocation local_; RemoteFileLocation remote_; @@ -83,6 +74,12 @@ class FileUploader final : public FileLoaderActor { PartsManager parts_manager_; std::map>> part_map_; + void set_resource_manager(ActorShared resource_manager) final; + + void update_priority(int8 priority) final; + + void update_resources(const ResourceState &other) final; + void on_error(Status status); Result start_part(Part part, int32 part_count) TD_WARN_UNUSED_RESULT;