Skip to content
This repository was archived by the owner on Aug 8, 2020. It is now read-only.

Commit f5418f0

Browse files
committed
Update FileManager.cpp
1 parent 90e1001 commit f5418f0

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

td/telegram/files/FileManager.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,14 +3844,16 @@ void FileManager::destroy_query(int32 file_id) {
38443844

38453845

38463846
void FileManager::memory_cleanup() {
3847+
std::lock_guard<std::shared_timed_mutex> writerLock(memory_cleanup_mutex);
3848+
38473849
LOG(ERROR) << "Initial registered ids: " << file_id_info_.size() << " registered nodes: " << file_nodes_.size();
38483850

3851+
std::unordered_set<int32> file_to_be_deleted = {};
3852+
38493853
/* DESTROY OLD file_id_info_ */
38503854
if (true) {
3851-
std::lock_guard<std::shared_timed_mutex> writerLock(memory_cleanup_mutex);
38523855
auto it = file_id_info_.begin();
38533856
auto time = std::time(nullptr);
3854-
std::vector<int32> file_to_be_deleted = {};
38553857

38563858
while (it != file_id_info_.end()) {
38573859
auto find_node = file_nodes_.find(it->second.node_id_);
@@ -3887,7 +3889,7 @@ void FileManager::memory_cleanup() {
38873889
destroy_query(file_id.fast_get());
38883890

38893891
/* DESTROY ASSOCIATED LATE */
3890-
file_to_be_deleted.push_back(file_id.fast_get());
3892+
file_to_be_deleted.insert(file_id.fast_get());
38913893
}
38923894

38933895
/* DESTROY MAIN QUERY */
@@ -3897,12 +3899,12 @@ void FileManager::memory_cleanup() {
38973899
file_nodes_.erase(it->second.node_id_);
38983900

38993901
/* DESTROY MAIN FILE LATE */
3900-
file_to_be_deleted.push_back(it->first);
3902+
file_to_be_deleted.insert(it->first);
39013903
}
39023904
}
39033905
} else {
39043906
/* The file has a nonexistent node associated */
3905-
file_to_be_deleted.push_back(it->first);
3907+
file_to_be_deleted.insert(it->first);
39063908
}
39073909

39083910
it++;
@@ -4057,9 +4059,17 @@ void FileManager::memory_cleanup() {
40574059

40584060
/* DESTROY INVALID remote_location_info_ */
40594061
if (true) {
4062+
std::set<int32> empty_remote_ids = {};
4063+
for (auto empty_remote_id : remote_location_info_.get_empty_id()) {
4064+
empty_remote_ids.insert(empty_remote_id);
4065+
}
40604066
auto map = remote_location_info_.get_map();
4067+
4068+
auto emptyIdsSize = empty_remote_ids.size();
4069+
auto mapSize = map.size();
4070+
40614071
auto it = map.begin();
4062-
while (it != map.end()) {
4072+
while (it != map.end() && (empty_remote_ids.find(it->second) == empty_remote_ids.end())) {
40634073
auto is_invalid = false;
40644074

40654075
auto find_file = file_id_info_.find(it->first.file_id_.fast_get());
@@ -4076,12 +4086,8 @@ void FileManager::memory_cleanup() {
40764086

40774087
if (is_invalid) {
40784088
remote_location_info_.erase(it->second);
4079-
// Todo: check if if the map must be emptied, or if it's ok to just add the emptied id with Enumerator erase
4080-
// it = map.erase(it);
4081-
it++;
4082-
} else {
4083-
it++;
40844089
}
4090+
it++;
40854091
}
40864092
}
40874093

0 commit comments

Comments
 (0)