Cache owned star count.

This commit is contained in:
levlam 2024-08-07 13:05:15 +03:00
parent 6d26481186
commit 9daa9a0717
3 changed files with 19 additions and 2 deletions

View File

@ -647,6 +647,18 @@ void StarManager::tear_down() {
parent_.reset();
}
td_api::object_ptr<td_api::updateOwnedStarCount> StarManager::get_update_owned_star_count_object() const {
return td_api::make_object<td_api::updateOwnedStarCount>(owned_star_count_);
}
void StarManager::on_update_owned_star_count(int64 star_count) {
if (star_count == owned_star_count_) {
return;
}
owned_star_count_ = star_count;
send_closure(G()->td(), &Td::send_update, get_update_owned_star_count_object());
}
Status StarManager::can_manage_stars(DialogId dialog_id, bool allow_self) const {
switch (dialog_id.get_type()) {
case DialogType::User: {

View File

@ -27,6 +27,8 @@ class StarManager final : public Actor {
public:
StarManager(Td *td, ActorShared<> parent);
void on_update_owned_star_count(int64 star_count);
void get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
void get_star_gift_payment_options(UserId user_id, Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
@ -77,9 +79,13 @@ class StarManager final : public Actor {
DialogId dialog_id, int64 star_count,
telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password, Promise<string> &&promise);
td_api::object_ptr<td_api::updateOwnedStarCount> get_update_owned_star_count_object() const;
Td *td_;
ActorShared<> parent_;
int64 owned_star_count_ = (1ll << 62);
FlatHashMap<DialogId, FlatHashMap<string, FileSourceId>, DialogIdHash> star_transaction_file_source_ids_[2];
};

View File

@ -4583,8 +4583,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateBroadcastRevenu
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStarsBalance> update, Promise<Unit> &&promise) {
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateOwnedStarCount>(StarManager::get_star_count(update->balance_, true)));
td_->star_manager_->on_update_owned_star_count(StarManager::get_star_count(update->balance_, true));
promise.set_value(Unit());
}