Use table_remove_if.
This commit is contained in:
parent
9e6d106585
commit
f5d8e4de83
@ -3442,15 +3442,8 @@ void ContactsManager::on_channel_participant_cache_timeout(ChannelId channel_id)
|
|||||||
|
|
||||||
auto &participants = channel_participants_it->second.participants_;
|
auto &participants = channel_participants_it->second.participants_;
|
||||||
auto min_access_date = G()->unix_time() - CHANNEL_PARTICIPANT_CACHE_TIME;
|
auto min_access_date = G()->unix_time() - CHANNEL_PARTICIPANT_CACHE_TIME;
|
||||||
vector<DialogId> to_delete_dialog_ids;
|
table_remove_if(participants,
|
||||||
for (auto it = participants.begin(); it != participants.end(); ++it) {
|
[min_access_date](const auto &it) { return it.second.last_access_date_ < min_access_date; });
|
||||||
if (it->second.last_access_date_ < min_access_date) {
|
|
||||||
to_delete_dialog_ids.push_back(it->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto dialog_id : to_delete_dialog_ids) {
|
|
||||||
participants.erase(dialog_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (participants.empty()) {
|
if (participants.empty()) {
|
||||||
channel_participants_.erase(channel_participants_it);
|
channel_participants_.erase(channel_participants_it);
|
||||||
|
@ -112,21 +112,17 @@ void FileStats::apply_dialog_ids(const vector<DialogId> &dialog_ids) {
|
|||||||
std::unordered_set<DialogId, DialogIdHash> all_dialogs(dialog_ids.begin(), dialog_ids.end());
|
std::unordered_set<DialogId, DialogIdHash> all_dialogs(dialog_ids.begin(), dialog_ids.end());
|
||||||
StatByType other_stats;
|
StatByType other_stats;
|
||||||
bool other_flag = false;
|
bool other_flag = false;
|
||||||
std::vector<DialogId> to_remove;
|
table_remove_if(stat_by_owner_dialog_id_, [&](const auto &it) {
|
||||||
for (auto it = stat_by_owner_dialog_id_.begin(); it != stat_by_owner_dialog_id_.end(); ++it) {
|
if (!all_dialogs.count(it.first)) {
|
||||||
if (!all_dialogs.count(it->first)) {
|
|
||||||
for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
|
for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
|
||||||
other_stats[i].size += it->second[i].size;
|
other_stats[i].size += it.second[i].size;
|
||||||
other_stats[i].cnt += it->second[i].cnt;
|
other_stats[i].cnt += it.second[i].cnt;
|
||||||
}
|
}
|
||||||
other_flag = true;
|
other_flag = true;
|
||||||
to_remove.push_back(it->first);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
for (auto id : to_remove) {
|
|
||||||
stat_by_owner_dialog_id_.erase(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (other_flag) {
|
if (other_flag) {
|
||||||
DialogId other_dialog_id; // prevents MSVC warning C4709: comma operator within array index expression
|
DialogId other_dialog_id; // prevents MSVC warning C4709: comma operator within array index expression
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "td/actor/PromiseFuture.h"
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
|
||||||
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
@ -215,14 +216,13 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
|
|||||||
void erase_by_prefix(Slice prefix) final {
|
void erase_by_prefix(Slice prefix) final {
|
||||||
auto lock = rw_mutex_.lock_write().move_as_ok();
|
auto lock = rw_mutex_.lock_write().move_as_ok();
|
||||||
vector<uint64> ids;
|
vector<uint64> ids;
|
||||||
for (auto it = map_.begin(); it != map_.end();) {
|
table_remove_if(map_, [&](const auto &it) {
|
||||||
if (begins_with(it->first, prefix)) {
|
if (begins_with(it.first, prefix)) {
|
||||||
ids.push_back(it->second.second);
|
ids.push_back(it.second.second);
|
||||||
it = map_.erase(it);
|
return true;
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
|
});
|
||||||
auto seq_no = binlog_->next_id(narrow_cast<int32>(ids.size()));
|
auto seq_no = binlog_->next_id(narrow_cast<int32>(ids.size()));
|
||||||
lock.reset();
|
lock.reset();
|
||||||
for (auto id : ids) {
|
for (auto id : ids) {
|
||||||
|
Loading…
Reference in New Issue
Block a user