Safer work with negative monotonic time.
This commit is contained in:
parent
e8cd3d9af2
commit
5cbf90e4a0
@ -138,6 +138,7 @@ AnimationsManager::AnimationsManager(Td *td, ActorShared<> parent) : td_(td), pa
|
||||
LOG(ERROR) << "Wrong saved animations limit = \"" << limit_string << "\" stored in database";
|
||||
}
|
||||
}
|
||||
next_saved_animations_load_time_ = Time::now();
|
||||
}
|
||||
|
||||
void AnimationsManager::tear_down() {
|
||||
@ -523,10 +524,10 @@ void AnimationsManager::reload_saved_animations(bool force) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!td_->auth_manager_->is_bot() && next_saved_animations_load_time_ >= 0 &&
|
||||
if (!td_->auth_manager_->is_bot() && !are_saved_animations_being_loaded_ &&
|
||||
(next_saved_animations_load_time_ < Time::now() || force)) {
|
||||
LOG_IF(INFO, force) << "Reload saved animations";
|
||||
next_saved_animations_load_time_ = -1;
|
||||
are_saved_animations_being_loaded_ = true;
|
||||
td_->create_handler<GetSavedGifsQuery>()->send(false, get_saved_animations_hash("reload_saved_animations"));
|
||||
}
|
||||
}
|
||||
@ -613,6 +614,7 @@ void AnimationsManager::on_get_saved_animations(
|
||||
bool is_repair, tl_object_ptr<telegram_api::messages_SavedGifs> &&saved_animations_ptr) {
|
||||
CHECK(!td_->auth_manager_->is_bot());
|
||||
if (!is_repair) {
|
||||
are_saved_animations_being_loaded_ = false;
|
||||
next_saved_animations_load_time_ = Time::now_cached() + Random::fast(30 * 60, 50 * 60);
|
||||
}
|
||||
|
||||
@ -667,6 +669,7 @@ void AnimationsManager::on_get_saved_animations(
|
||||
void AnimationsManager::on_get_saved_animations_failed(bool is_repair, Status error) {
|
||||
CHECK(error.is_error());
|
||||
if (!is_repair) {
|
||||
are_saved_animations_being_loaded_ = false;
|
||||
next_saved_animations_load_time_ = Time::now_cached() + Random::fast(5, 10);
|
||||
}
|
||||
auto &queries = is_repair ? repair_saved_animations_queries_ : load_saved_animations_queries_;
|
||||
|
@ -151,6 +151,7 @@ class AnimationsManager : public Actor {
|
||||
vector<FileId> saved_animation_ids_;
|
||||
vector<FileId> saved_animation_file_ids_;
|
||||
double next_saved_animations_load_time_ = 0;
|
||||
bool are_saved_animations_being_loaded_ = false;
|
||||
bool are_saved_animations_loaded_ = false;
|
||||
vector<Promise<Unit>> load_saved_animations_queries_;
|
||||
vector<Promise<Unit>> repair_saved_animations_queries_;
|
||||
|
@ -163,6 +163,7 @@ class SetInlineBotResultsQuery : public Td::ResultHandler {
|
||||
InlineQueriesManager::InlineQueriesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
drop_inline_query_result_timeout_.set_callback(on_drop_inline_query_result_timeout_callback);
|
||||
drop_inline_query_result_timeout_.set_callback_data(static_cast<void *>(this));
|
||||
next_inline_query_time_ = Time::now();
|
||||
}
|
||||
|
||||
void InlineQueriesManager::tear_down() {
|
||||
|
@ -126,7 +126,7 @@ class InlineQueriesManager : public Actor {
|
||||
Promise<Unit> promise;
|
||||
};
|
||||
|
||||
double next_inline_query_time_ = -1.0;
|
||||
double next_inline_query_time_ = 0.0;
|
||||
unique_ptr<PendingInlineQuery> pending_inline_query_;
|
||||
NetQueryRef sent_query_;
|
||||
|
||||
|
@ -724,8 +724,8 @@ void PasswordManager::cache_secret(secure_storage::Secret secret) {
|
||||
secret_ = std::move(secret);
|
||||
|
||||
const int32 max_cache_time = 3600;
|
||||
secret_expire_date_ = Time::now() + max_cache_time;
|
||||
set_timeout_at(secret_expire_date_);
|
||||
secret_expire_time_ = Time::now() + max_cache_time;
|
||||
set_timeout_at(secret_expire_time_);
|
||||
}
|
||||
|
||||
void PasswordManager::drop_cached_secret() {
|
||||
@ -734,8 +734,10 @@ void PasswordManager::drop_cached_secret() {
|
||||
}
|
||||
|
||||
void PasswordManager::timeout_expired() {
|
||||
if (Time::now() >= secret_expire_date_) {
|
||||
if (Time::now() >= secret_expire_time_) {
|
||||
drop_cached_secret();
|
||||
} else {
|
||||
set_timeout_at(secret_expire_time_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ class PasswordManager : public NetQueryCallback {
|
||||
};
|
||||
|
||||
optional<secure_storage::Secret> secret_;
|
||||
double secret_expire_date_ = 0;
|
||||
double secret_expire_time_ = 0;
|
||||
|
||||
TempPasswordState temp_password_state_;
|
||||
Promise<TempState> create_temp_password_promise_;
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
QueryCombiner::QueryCombiner(Slice name, double min_delay) : next_query_time_(Time::now()), min_delay_(min_delay) {
|
||||
register_actor(name, this).release();
|
||||
}
|
||||
|
||||
void QueryCombiner::add_query(int64 query_id, Promise<Promise<Unit>> &&send_query, Promise<Unit> &&promise) {
|
||||
LOG(INFO) << "Add query " << query_id;
|
||||
auto &query = queries_[query_id];
|
||||
|
@ -21,9 +21,7 @@ namespace td {
|
||||
// combines identical queries into one request
|
||||
class QueryCombiner : public Actor {
|
||||
public:
|
||||
explicit QueryCombiner(Slice name, double min_delay = 0) : min_delay_(min_delay) {
|
||||
register_actor(name, this).release();
|
||||
}
|
||||
QueryCombiner(Slice name, double min_delay);
|
||||
|
||||
void add_query(int64 query_id, Promise<Promise<Unit>> &&send_query, Promise<Unit> &&promise);
|
||||
|
||||
@ -36,7 +34,7 @@ class QueryCombiner : public Actor {
|
||||
|
||||
int32 query_count_ = 0;
|
||||
|
||||
double next_query_time_ = 0.0;
|
||||
double next_query_time_;
|
||||
double min_delay_;
|
||||
|
||||
std::queue<int64> delayed_queries_;
|
||||
|
@ -1860,9 +1860,9 @@ void StickersManager::reload_installed_sticker_sets(bool is_masks, bool force) {
|
||||
}
|
||||
|
||||
auto &next_load_time = next_installed_sticker_sets_load_time_[is_masks];
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= 0 && (next_load_time < Time::now() || force)) {
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= -9e9 && (next_load_time < Time::now() || force)) {
|
||||
LOG_IF(INFO, force) << "Reload sticker sets";
|
||||
next_load_time = -1;
|
||||
next_load_time = -1e10;
|
||||
td_->create_handler<GetAllStickersQuery>()->send(is_masks, installed_sticker_sets_hash_[is_masks]);
|
||||
}
|
||||
}
|
||||
@ -1872,10 +1872,10 @@ void StickersManager::reload_featured_sticker_sets(bool force) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!td_->auth_manager_->is_bot() && next_featured_sticker_sets_load_time_ >= 0 &&
|
||||
(next_featured_sticker_sets_load_time_ < Time::now() || force)) {
|
||||
auto &next_load_time = next_featured_sticker_sets_load_time_;
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= -9e9 && (next_load_time < Time::now() || force)) {
|
||||
LOG_IF(INFO, force) << "Reload trending sticker sets";
|
||||
next_featured_sticker_sets_load_time_ = -1;
|
||||
next_load_time = -1e10;
|
||||
td_->create_handler<GetFeaturedStickerSetsQuery>()->send(featured_sticker_sets_hash_);
|
||||
}
|
||||
}
|
||||
@ -4985,9 +4985,9 @@ void StickersManager::reload_recent_stickers(bool is_attached, bool force) {
|
||||
}
|
||||
|
||||
auto &next_load_time = next_recent_stickers_load_time_[is_attached];
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= 0 && (next_load_time < Time::now() || force)) {
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= -9e9 && (next_load_time < Time::now() || force)) {
|
||||
LOG_IF(INFO, force) << "Reload recent " << (is_attached ? "attached " : "") << "stickers";
|
||||
next_load_time = -1;
|
||||
next_load_time = -1e10;
|
||||
td_->create_handler<GetRecentStickersQuery>()->send(false, is_attached, recent_stickers_hash_[is_attached]);
|
||||
}
|
||||
}
|
||||
@ -5405,10 +5405,10 @@ void StickersManager::reload_favorite_stickers(bool force) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!td_->auth_manager_->is_bot() && next_favorite_stickers_load_time_ >= 0 &&
|
||||
(next_favorite_stickers_load_time_ < Time::now() || force)) {
|
||||
auto &next_load_time = next_favorite_stickers_load_time_;
|
||||
if (!td_->auth_manager_->is_bot() && next_load_time >= -9e9 && (next_load_time < Time::now() || force)) {
|
||||
LOG_IF(INFO, force) << "Reload favorite stickers";
|
||||
next_favorite_stickers_load_time_ = -1;
|
||||
next_load_time = -1e10;
|
||||
td_->create_handler<GetFavedStickersQuery>()->send(false, get_favorite_stickers_hash());
|
||||
}
|
||||
}
|
||||
|
@ -630,10 +630,10 @@ class StickersManager : public Actor {
|
||||
vector<FileId> recent_sticker_ids_[2];
|
||||
vector<FileId> favorite_sticker_ids_;
|
||||
|
||||
double next_installed_sticker_sets_load_time_[2] = {0, 0};
|
||||
double next_featured_sticker_sets_load_time_ = 0;
|
||||
double next_recent_stickers_load_time_[2] = {0, 0};
|
||||
double next_favorite_stickers_load_time_ = 0;
|
||||
double next_installed_sticker_sets_load_time_[2] = {-1e10, -1e10};
|
||||
double next_featured_sticker_sets_load_time_ = -1e10;
|
||||
double next_recent_stickers_load_time_[2] = {-1e10, -1e10};
|
||||
double next_favorite_stickers_load_time_ = -1e10;
|
||||
|
||||
int32 installed_sticker_sets_hash_[2] = {0, 0};
|
||||
int32 featured_sticker_sets_hash_ = 0;
|
||||
|
@ -130,8 +130,8 @@ void GetHostByNameActor::run(string host, int port, bool prefer_ipv6, Promise<IP
|
||||
}
|
||||
auto ascii_host = r_ascii_host.move_as_ok();
|
||||
|
||||
auto &value = cache_[prefer_ipv6].emplace(ascii_host, Value{{}, 0}).first->second;
|
||||
auto begin_time = Time::now();
|
||||
auto &value = cache_[prefer_ipv6].emplace(ascii_host, Value{{}, begin_time - 1.0}).first->second;
|
||||
if (value.expires_at > begin_time) {
|
||||
return promise.set_result(value.get_ip_port(port));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user