Use data from the database for max_dialog_date.
GitOrigin-RevId: a1dc2d8ecf64a68209637bb1ce0d16a8b661770c
This commit is contained in:
parent
74219aa2d3
commit
003aee4268
@ -201,8 +201,8 @@ class DialogDbImpl : public DialogDbSyncInterface {
|
|||||||
get_last_notification_date(get_notification_group_stmt_, 1));
|
get_last_notification_date(get_notification_group_stmt_, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<vector<BufferSlice>> get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit) override {
|
Result<DialogDbGetDialogsResult> get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id,
|
||||||
// TODO use folder_id
|
int32 limit) override {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
get_dialogs_stmt_.reset();
|
get_dialogs_stmt_.reset();
|
||||||
};
|
};
|
||||||
@ -212,18 +212,18 @@ class DialogDbImpl : public DialogDbSyncInterface {
|
|||||||
get_dialogs_stmt_.bind_int64(3, dialog_id.get()).ensure();
|
get_dialogs_stmt_.bind_int64(3, dialog_id.get()).ensure();
|
||||||
get_dialogs_stmt_.bind_int32(4, limit).ensure();
|
get_dialogs_stmt_.bind_int32(4, limit).ensure();
|
||||||
|
|
||||||
vector<BufferSlice> dialogs;
|
DialogDbGetDialogsResult result;
|
||||||
TRY_STATUS(get_dialogs_stmt_.step());
|
TRY_STATUS(get_dialogs_stmt_.step());
|
||||||
while (get_dialogs_stmt_.has_row()) {
|
while (get_dialogs_stmt_.has_row()) {
|
||||||
BufferSlice data(get_dialogs_stmt_.view_blob(0));
|
BufferSlice data(get_dialogs_stmt_.view_blob(0));
|
||||||
auto loaded_dialog_id = get_dialogs_stmt_.view_int64(1);
|
result.next_dialog_id = DialogId(get_dialogs_stmt_.view_int64(1));
|
||||||
auto loaded_dialog_order = get_dialogs_stmt_.view_int64(2);
|
result.next_order = get_dialogs_stmt_.view_int64(2);
|
||||||
LOG(INFO) << "Load chat " << loaded_dialog_id << " with order " << loaded_dialog_order;
|
LOG(INFO) << "Load " << result.next_dialog_id << " with order " << result.next_order;
|
||||||
dialogs.emplace_back(std::move(data));
|
result.dialogs.emplace_back(std::move(data));
|
||||||
TRY_STATUS(get_dialogs_stmt_.step());
|
TRY_STATUS(get_dialogs_stmt_.step());
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::move(dialogs);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
Result<vector<NotificationGroupKey>> get_notification_groups_by_last_notification_date(
|
Result<vector<NotificationGroupKey>> get_notification_groups_by_last_notification_date(
|
||||||
NotificationGroupKey notification_group_key, int32 limit) override {
|
NotificationGroupKey notification_group_key, int32 limit) override {
|
||||||
@ -319,7 +319,7 @@ class DialogDbAsync : public DialogDbAsyncInterface {
|
|||||||
send_closure_later(impl_, &Impl::get_dialog, dialog_id, std::move(promise));
|
send_closure_later(impl_, &Impl::get_dialog, dialog_id, std::move(promise));
|
||||||
}
|
}
|
||||||
void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) override {
|
Promise<DialogDbGetDialogsResult> promise) override {
|
||||||
send_closure_later(impl_, &Impl::get_dialogs, folder_id, order, dialog_id, limit, std::move(promise));
|
send_closure_later(impl_, &Impl::get_dialogs, folder_id, order, dialog_id, limit, std::move(promise));
|
||||||
}
|
}
|
||||||
void close(Promise<> promise) override {
|
void close(Promise<> promise) override {
|
||||||
@ -357,7 +357,7 @@ class DialogDbAsync : public DialogDbAsyncInterface {
|
|||||||
promise.set_result(sync_db_->get_dialog(dialog_id));
|
promise.set_result(sync_db_->get_dialog(dialog_id));
|
||||||
}
|
}
|
||||||
void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) {
|
Promise<DialogDbGetDialogsResult> promise) {
|
||||||
add_read_query();
|
add_read_query();
|
||||||
promise.set_result(sync_db_->get_dialogs(folder_id, order, dialog_id, limit));
|
promise.set_result(sync_db_->get_dialogs(folder_id, order, dialog_id, limit));
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,12 @@ namespace td {
|
|||||||
class SqliteConnectionSafe;
|
class SqliteConnectionSafe;
|
||||||
class SqliteDb;
|
class SqliteDb;
|
||||||
|
|
||||||
|
struct DialogDbGetDialogsResult {
|
||||||
|
vector<BufferSlice> dialogs;
|
||||||
|
int64 next_order = 0;
|
||||||
|
DialogId next_dialog_id;
|
||||||
|
};
|
||||||
|
|
||||||
class DialogDbSyncInterface {
|
class DialogDbSyncInterface {
|
||||||
public:
|
public:
|
||||||
DialogDbSyncInterface() = default;
|
DialogDbSyncInterface() = default;
|
||||||
@ -37,7 +43,8 @@ class DialogDbSyncInterface {
|
|||||||
|
|
||||||
virtual Result<BufferSlice> get_dialog(DialogId dialog_id) = 0;
|
virtual Result<BufferSlice> get_dialog(DialogId dialog_id) = 0;
|
||||||
|
|
||||||
virtual Result<vector<BufferSlice>> get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit) = 0;
|
virtual Result<DialogDbGetDialogsResult> get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id,
|
||||||
|
int32 limit) = 0;
|
||||||
|
|
||||||
virtual Result<vector<NotificationGroupKey>> get_notification_groups_by_last_notification_date(
|
virtual Result<vector<NotificationGroupKey>> get_notification_groups_by_last_notification_date(
|
||||||
NotificationGroupKey notification_group_key, int32 limit) = 0;
|
NotificationGroupKey notification_group_key, int32 limit) = 0;
|
||||||
@ -71,7 +78,7 @@ class DialogDbAsyncInterface {
|
|||||||
virtual void get_dialog(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
virtual void get_dialog(DialogId dialog_id, Promise<BufferSlice> promise) = 0;
|
||||||
|
|
||||||
virtual void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
virtual void get_dialogs(FolderId folder_id, int64 order, DialogId dialog_id, int32 limit,
|
||||||
Promise<vector<BufferSlice>> promise) = 0;
|
Promise<DialogDbGetDialogsResult> promise) = 0;
|
||||||
|
|
||||||
virtual void get_notification_groups_by_last_notification_date(NotificationGroupKey notification_group_key,
|
virtual void get_notification_groups_by_last_notification_date(NotificationGroupKey notification_group_key,
|
||||||
int32 limit,
|
int32 limit,
|
||||||
|
@ -12114,27 +12114,26 @@ void MessagesManager::load_dialog_list_from_database(FolderId folder_id, int32 l
|
|||||||
folder_id, list.last_loaded_database_dialog_date_.get_order(),
|
folder_id, list.last_loaded_database_dialog_date_.get_order(),
|
||||||
list.last_loaded_database_dialog_date_.get_dialog_id(), limit,
|
list.last_loaded_database_dialog_date_.get_dialog_id(), limit,
|
||||||
PromiseCreator::lambda([actor_id = actor_id(this), folder_id, limit,
|
PromiseCreator::lambda([actor_id = actor_id(this), folder_id, limit,
|
||||||
promise = std::move(promise)](vector<BufferSlice> result) mutable {
|
promise = std::move(promise)](DialogDbGetDialogsResult result) mutable {
|
||||||
send_closure(actor_id, &MessagesManager::on_get_dialogs_from_database, folder_id, limit, std::move(result),
|
send_closure(actor_id, &MessagesManager::on_get_dialogs_from_database, folder_id, limit, std::move(result),
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_get_dialogs_from_database(FolderId folder_id, int32 limit, vector<BufferSlice> &&dialogs,
|
void MessagesManager::on_get_dialogs_from_database(FolderId folder_id, int32 limit, DialogDbGetDialogsResult &&dialogs,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
auto &list = get_dialog_list(folder_id);
|
auto &list = get_dialog_list(folder_id);
|
||||||
LOG(INFO) << "Receive " << dialogs.size() << " from expected " << limit << " chats in " << folder_id
|
LOG(INFO) << "Receive " << dialogs.dialogs.size() << " from expected " << limit << " chats in " << folder_id
|
||||||
<< " in from database";
|
<< " in from database with next order " << dialogs.next_order << " and next " << dialogs.next_dialog_id;
|
||||||
int32 new_get_dialogs_limit = 0;
|
int32 new_get_dialogs_limit = 0;
|
||||||
int32 have_more_dialogs_in_database = (limit == static_cast<int32>(dialogs.size()));
|
int32 have_more_dialogs_in_database = (limit == static_cast<int32>(dialogs.dialogs.size()));
|
||||||
if (have_more_dialogs_in_database && limit < list.load_dialog_list_limit_max_) {
|
if (have_more_dialogs_in_database && limit < list.load_dialog_list_limit_max_) {
|
||||||
new_get_dialogs_limit = list.load_dialog_list_limit_max_ - limit;
|
new_get_dialogs_limit = list.load_dialog_list_limit_max_ - limit;
|
||||||
}
|
}
|
||||||
list.load_dialog_list_limit_max_ = 0;
|
list.load_dialog_list_limit_max_ = 0;
|
||||||
|
|
||||||
DialogDate max_dialog_date = MIN_DIALOG_DATE;
|
|
||||||
size_t dialogs_skipped = 0;
|
size_t dialogs_skipped = 0;
|
||||||
for (auto &dialog : dialogs) {
|
for (auto &dialog : dialogs.dialogs) {
|
||||||
Dialog *d = on_load_dialog_from_database(DialogId(), std::move(dialog));
|
Dialog *d = on_load_dialog_from_database(DialogId(), std::move(dialog));
|
||||||
if (d == nullptr) {
|
if (d == nullptr) {
|
||||||
dialogs_skipped++;
|
dialogs_skipped++;
|
||||||
@ -12147,13 +12146,10 @@ void MessagesManager::on_get_dialogs_from_database(FolderId folder_id, int32 lim
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogDate dialog_date(d->order, d->dialog_id);
|
LOG(INFO) << "Chat " << d->dialog_id << " with order " << d->order << " is loaded from database";
|
||||||
if (max_dialog_date < dialog_date) {
|
|
||||||
max_dialog_date = dialog_date;
|
|
||||||
}
|
|
||||||
LOG(INFO) << "Chat " << dialog_date << " is loaded from database";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DialogDate max_dialog_date(dialogs.next_order, dialogs.next_dialog_id);
|
||||||
if (!have_more_dialogs_in_database) {
|
if (!have_more_dialogs_in_database) {
|
||||||
list.last_loaded_database_dialog_date_ = MAX_DIALOG_DATE;
|
list.last_loaded_database_dialog_date_ = MAX_DIALOG_DATE;
|
||||||
LOG(INFO) << "Set last loaded database dialog date to " << list.last_loaded_database_dialog_date_;
|
LOG(INFO) << "Set last loaded database dialog date to " << list.last_loaded_database_dialog_date_;
|
||||||
@ -12168,7 +12164,7 @@ void MessagesManager::on_get_dialogs_from_database(FolderId folder_id, int32 lim
|
|||||||
update_last_dialog_date(folder_id);
|
update_last_dialog_date(folder_id);
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Last loaded database dialog date didn't increased, skipped " << dialogs_skipped << " chats out of "
|
LOG(ERROR) << "Last loaded database dialog date didn't increased, skipped " << dialogs_skipped << " chats out of "
|
||||||
<< dialogs.size();
|
<< dialogs.dialogs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(list.last_loaded_database_dialog_date_ < list.last_database_server_dialog_date_)) {
|
if (!(list.last_loaded_database_dialog_date_ < list.last_database_server_dialog_date_)) {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/Dependencies.h"
|
#include "td/telegram/Dependencies.h"
|
||||||
#include "td/telegram/DialogDate.h"
|
#include "td/telegram/DialogDate.h"
|
||||||
|
#include "td/telegram/DialogDb.h"
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
#include "td/telegram/DialogParticipant.h"
|
#include "td/telegram/DialogParticipant.h"
|
||||||
#include "td/telegram/files/FileId.h"
|
#include "td/telegram/files/FileId.h"
|
||||||
@ -1930,7 +1931,7 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
Dialog *on_load_dialog_from_database(DialogId dialog_id, const BufferSlice &value);
|
Dialog *on_load_dialog_from_database(DialogId dialog_id, const BufferSlice &value);
|
||||||
|
|
||||||
void on_get_dialogs_from_database(FolderId folder_id, int32 limit, vector<BufferSlice> &&dialogs,
|
void on_get_dialogs_from_database(FolderId folder_id, int32 limit, DialogDbGetDialogsResult &&dialogs,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id = 0);
|
void send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id = 0);
|
||||||
|
Reference in New Issue
Block a user