From 46ddfccaf1f636e7b27b6ebbe982c76c708d683a Mon Sep 17 00:00:00 2001 From: "andrew (from workstation)" Date: Wed, 20 May 2020 18:27:16 +0200 Subject: [PATCH] update time on get --- td/telegram/files/FileId.h | 10 +++++++++- td/telegram/files/FileManager.cpp | 5 +---- td/telegram/files/FileManager.h | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/td/telegram/files/FileId.h b/td/telegram/files/FileId.h index 43bdc56e..fce3e99f 100644 --- a/td/telegram/files/FileId.h +++ b/td/telegram/files/FileId.h @@ -17,6 +17,7 @@ namespace td { class FileId { int32 id = 0; int32 remote_id = 0; + int64 time = INT64_MAX; public: FileId() = default; @@ -34,10 +35,17 @@ class FileId { return id > 0; } - int32 get() const { + int32 get() { + time = std::time(nullptr); return id; } + int64 get_time() { + auto res = time; + time = INT64_MAX; + return res; + } + int32 get_remote() const { return remote_id; } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 9a4c0967..f2ce863c 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2941,13 +2941,11 @@ FileId FileManager::next_file_id() { if (!empty_file_ids_.empty()) { auto res = empty_file_ids_.back(); empty_file_ids_.pop_back(); - file_id_insert_time_[res] = std::time(nullptr); return FileId{res, 0}; } auto id = (int32) file_id_info_.size(); FileId res(static_cast(id), 0); - file_id_insert_time_[id] = std::time(nullptr); file_id_info_.push_back({}); return res; } @@ -3488,8 +3486,7 @@ void FileManager::memory_cleanup() { if (main_node_id != 0) { auto &node = file_nodes_[main_node_id]; if (node != nullptr && ((int32) i) == node->main_file_id_.get()) { - if (time - file_id_insert_time_[i] > 60 * 5 /* MAIN FILE TTL */) { - file_id_insert_time_[i] = INT64_MAX; + if (time - node->main_file_id_.get_time() > 60 * 5 /* MAIN FILE TTL */) { for (auto &file_id : node->file_ids_) { /* DESTROY ASSOCIATED QUERIES */ destroy_query(file_id.get()); diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 6ed08764..4beb5d0b 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -559,7 +559,6 @@ class FileManager : public FileLoadManager::Callback { std::map local_location_to_file_id_; std::map generate_location_to_file_id_; std::map pmc_id_to_file_node_id_; - std::unordered_map file_id_insert_time_; std::vector file_id_info_; vector empty_file_ids_;