Add get_log_event_storer convenience method.

GitOrigin-RevId: 0651bb08a5c41917b69836140e3ff512ab571571
This commit is contained in:
levlam 2020-09-22 01:39:45 +03:00
parent 08ff725767
commit 9a8895e043
6 changed files with 84 additions and 86 deletions

View File

@ -7314,7 +7314,7 @@ void ContactsManager::save_user(User *u, UserId user_id, bool from_binlog) {
if (!u->is_saved || !u->is_status_saved) { // TODO more effective handling of !u->is_status_saved if (!u->is_saved || !u->is_status_saved) { // TODO more effective handling of !u->is_status_saved
if (!from_binlog) { if (!from_binlog) {
auto logevent = UserLogEvent(user_id, *u); auto logevent = UserLogEvent(user_id, *u);
auto storer = LogEventStorerImpl<UserLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
if (u->logevent_id == 0) { if (u->logevent_id == 0) {
u->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer); u->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer);
} else { } else {
@ -7590,7 +7590,7 @@ void ContactsManager::save_chat(Chat *c, ChatId chat_id, bool from_binlog) {
if (!c->is_saved) { if (!c->is_saved) {
if (!from_binlog) { if (!from_binlog) {
auto logevent = ChatLogEvent(chat_id, *c); auto logevent = ChatLogEvent(chat_id, *c);
auto storer = LogEventStorerImpl<ChatLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer);
} else { } else {
@ -7826,7 +7826,7 @@ void ContactsManager::save_channel(Channel *c, ChannelId channel_id, bool from_b
if (!c->is_saved) { if (!c->is_saved) {
if (!from_binlog) { if (!from_binlog) {
auto logevent = ChannelLogEvent(channel_id, *c); auto logevent = ChannelLogEvent(channel_id, *c);
auto storer = LogEventStorerImpl<ChannelLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer);
} else { } else {
@ -8076,7 +8076,7 @@ void ContactsManager::save_secret_chat(SecretChat *c, SecretChatId secret_chat_i
if (!c->is_saved) { if (!c->is_saved) {
if (!from_binlog) { if (!from_binlog) {
auto logevent = SecretChatLogEvent(secret_chat_id, *c); auto logevent = SecretChatLogEvent(secret_chat_id, *c);
auto storer = LogEventStorerImpl<SecretChatLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
if (c->logevent_id == 0) { if (c->logevent_id == 0) {
c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer); c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer);
} else { } else {

View File

@ -7741,8 +7741,8 @@ class MessagesManager::ChangeDialogReportSpamStateOnServerLogEvent {
uint64 MessagesManager::save_change_dialog_report_spam_state_on_server_logevent(DialogId dialog_id, uint64 MessagesManager::save_change_dialog_report_spam_state_on_server_logevent(DialogId dialog_id,
bool is_spam_dialog) { bool is_spam_dialog) {
ChangeDialogReportSpamStateOnServerLogEvent logevent{dialog_id, is_spam_dialog}; ChangeDialogReportSpamStateOnServerLogEvent logevent{dialog_id, is_spam_dialog};
auto storer = LogEventStorerImpl<ChangeDialogReportSpamStateOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_id, bool is_spam_dialog, void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_id, bool is_spam_dialog,
@ -9720,8 +9720,8 @@ class MessagesManager::DeleteMessagesFromServerLogEvent {
uint64 MessagesManager::save_delete_messages_from_server_logevent(DialogId dialog_id, uint64 MessagesManager::save_delete_messages_from_server_logevent(DialogId dialog_id,
const vector<MessageId> &message_ids, bool revoke) { const vector<MessageId> &message_ids, bool revoke) {
DeleteMessagesFromServerLogEvent logevent{dialog_id, message_ids, revoke}; DeleteMessagesFromServerLogEvent logevent{dialog_id, message_ids, revoke};
auto storer = LogEventStorerImpl<DeleteMessagesFromServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessagesFromServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessagesFromServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, void MessagesManager::delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke,
@ -9793,8 +9793,8 @@ class MessagesManager::DeleteScheduledMessagesFromServerLogEvent {
uint64 MessagesManager::save_delete_scheduled_messages_from_server_logevent(DialogId dialog_id, uint64 MessagesManager::save_delete_scheduled_messages_from_server_logevent(DialogId dialog_id,
const vector<MessageId> &message_ids) { const vector<MessageId> &message_ids) {
DeleteScheduledMessagesFromServerLogEvent logevent{dialog_id, message_ids}; DeleteScheduledMessagesFromServerLogEvent logevent{dialog_id, message_ids};
auto storer = LogEventStorerImpl<DeleteScheduledMessagesFromServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteScheduledMessagesFromServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteScheduledMessagesFromServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::delete_scheduled_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, void MessagesManager::delete_scheduled_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids,
@ -9923,8 +9923,8 @@ class MessagesManager::DeleteDialogHistoryFromServerLogEvent {
uint64 MessagesManager::save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id, uint64 MessagesManager::save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id,
bool remove_from_dialog_list, bool revoke) { bool remove_from_dialog_list, bool revoke) {
DeleteDialogHistoryFromServerLogEvent logevent{dialog_id, max_message_id, remove_from_dialog_list, revoke}; DeleteDialogHistoryFromServerLogEvent logevent{dialog_id, max_message_id, remove_from_dialog_list, revoke};
auto storer = LogEventStorerImpl<DeleteDialogHistoryFromServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteDialogHistoryFromServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteDialogHistoryFromServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id, void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id,
@ -10153,9 +10153,8 @@ class MessagesManager::DeleteAllChannelMessagesFromUserOnServerLogEvent {
uint64 MessagesManager::save_delete_all_channel_messages_from_user_on_server_logevent(ChannelId channel_id, uint64 MessagesManager::save_delete_all_channel_messages_from_user_on_server_logevent(ChannelId channel_id,
UserId user_id) { UserId user_id) {
DeleteAllChannelMessagesFromUserOnServerLogEvent logevent{channel_id, user_id}; DeleteAllChannelMessagesFromUserOnServerLogEvent logevent{channel_id, user_id};
auto storer = LogEventStorerImpl<DeleteAllChannelMessagesFromUserOnServerLogEvent>(logevent);
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer, return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer,
storer); get_log_event_storer(logevent));
} }
void MessagesManager::delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id, void MessagesManager::delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id,
@ -10385,8 +10384,8 @@ class MessagesManager::ReadAllDialogMentionsOnServerLogEvent {
uint64 MessagesManager::save_read_all_dialog_mentions_on_server_logevent(DialogId dialog_id) { uint64 MessagesManager::save_read_all_dialog_mentions_on_server_logevent(DialogId dialog_id) {
ReadAllDialogMentionsOnServerLogEvent logevent{dialog_id}; ReadAllDialogMentionsOnServerLogEvent logevent{dialog_id};
auto storer = LogEventStorerImpl<ReadAllDialogMentionsOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogMentionsOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogMentionsOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 logevent_id, void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 logevent_id,
@ -17294,8 +17293,7 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id,
if (G()->parameters().use_message_db) { if (G()->parameters().use_message_db) {
SaveDialogDraftMessageOnServerLogEvent logevent; SaveDialogDraftMessageOnServerLogEvent logevent;
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
add_log_event(d->save_draft_message_logevent_id, add_log_event(d->save_draft_message_logevent_id, get_log_event_storer(logevent),
LogEventStorerImpl<SaveDialogDraftMessageOnServerLogEvent>(logevent),
LogEvent::HandlerType::SaveDialogDraftMessageOnServer, "draft"); LogEvent::HandlerType::SaveDialogDraftMessageOnServer, "draft");
} }
@ -17484,8 +17482,8 @@ class MessagesManager::ToggleDialogIsPinnedOnServerLogEvent {
uint64 MessagesManager::save_toggle_dialog_is_pinned_on_server_logevent(DialogId dialog_id, bool is_pinned) { uint64 MessagesManager::save_toggle_dialog_is_pinned_on_server_logevent(DialogId dialog_id, bool is_pinned) {
ToggleDialogIsPinnedOnServerLogEvent logevent{dialog_id, is_pinned}; ToggleDialogIsPinnedOnServerLogEvent logevent{dialog_id, is_pinned};
auto storer = LogEventStorerImpl<ToggleDialogIsPinnedOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsPinnedOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsPinnedOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id) { void MessagesManager::toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id) {
@ -17644,8 +17642,8 @@ class MessagesManager::ReorderPinnedDialogsOnServerLogEvent {
uint64 MessagesManager::save_reorder_pinned_dialogs_on_server_logevent(FolderId folder_id, uint64 MessagesManager::save_reorder_pinned_dialogs_on_server_logevent(FolderId folder_id,
const vector<DialogId> &dialog_ids) { const vector<DialogId> &dialog_ids) {
ReorderPinnedDialogsOnServerLogEvent logevent{folder_id, dialog_ids}; ReorderPinnedDialogsOnServerLogEvent logevent{folder_id, dialog_ids};
auto storer = LogEventStorerImpl<ReorderPinnedDialogsOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReorderPinnedDialogsOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReorderPinnedDialogsOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::reorder_pinned_dialogs_on_server(FolderId folder_id, const vector<DialogId> &dialog_ids, void MessagesManager::reorder_pinned_dialogs_on_server(FolderId folder_id, const vector<DialogId> &dialog_ids,
@ -17703,8 +17701,8 @@ class MessagesManager::ToggleDialogIsMarkedAsUnreadOnServerLogEvent {
uint64 MessagesManager::save_toggle_dialog_is_marked_as_unread_on_server_logevent(DialogId dialog_id, uint64 MessagesManager::save_toggle_dialog_is_marked_as_unread_on_server_logevent(DialogId dialog_id,
bool is_marked_as_unread) { bool is_marked_as_unread) {
ToggleDialogIsMarkedAsUnreadOnServerLogEvent logevent{dialog_id, is_marked_as_unread}; ToggleDialogIsMarkedAsUnreadOnServerLogEvent logevent{dialog_id, is_marked_as_unread};
auto storer = LogEventStorerImpl<ToggleDialogIsMarkedAsUnreadOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread, void MessagesManager::toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread,
@ -17774,8 +17772,8 @@ class MessagesManager::ToggleDialogIsBlockedOnServerLogEvent {
uint64 MessagesManager::save_toggle_dialog_is_blocked_on_server_logevent(DialogId dialog_id, bool is_blocked) { uint64 MessagesManager::save_toggle_dialog_is_blocked_on_server_logevent(DialogId dialog_id, bool is_blocked) {
ToggleDialogIsBlockedOnServerLogEvent logevent{dialog_id, is_blocked}; ToggleDialogIsBlockedOnServerLogEvent logevent{dialog_id, is_blocked};
auto storer = LogEventStorerImpl<ToggleDialogIsBlockedOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsBlockedOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsBlockedOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 logevent_id) { void MessagesManager::toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 logevent_id) {
@ -17841,8 +17839,7 @@ void MessagesManager::update_dialog_notification_settings_on_server(DialogId dia
if (!from_binlog && G()->parameters().use_message_db) { if (!from_binlog && G()->parameters().use_message_db) {
UpdateDialogNotificationSettingsOnServerLogEvent logevent; UpdateDialogNotificationSettingsOnServerLogEvent logevent;
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
add_log_event(d->save_notification_settings_logevent_id, add_log_event(d->save_notification_settings_logevent_id, get_log_event_storer(logevent),
LogEventStorerImpl<UpdateDialogNotificationSettingsOnServerLogEvent>(logevent),
LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, "notification settings"); LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, "notification settings");
} }
@ -18307,8 +18304,8 @@ class MessagesManager::ReadMessageContentsOnServerLogEvent {
uint64 MessagesManager::save_read_message_contents_on_server_logevent(DialogId dialog_id, uint64 MessagesManager::save_read_message_contents_on_server_logevent(DialogId dialog_id,
const vector<MessageId> &message_ids) { const vector<MessageId> &message_ids) {
ReadMessageContentsOnServerLogEvent logevent{dialog_id, message_ids}; ReadMessageContentsOnServerLogEvent logevent{dialog_id, message_ids};
auto storer = LogEventStorerImpl<ReadMessageContentsOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadMessageContentsOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadMessageContentsOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector<MessageId> message_ids, void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector<MessageId> message_ids,
@ -18935,8 +18932,8 @@ class MessagesManager::UpdateScopeNotificationSettingsOnServerLogEvent {
uint64 MessagesManager::save_update_scope_notification_settings_on_server_logevent(NotificationSettingsScope scope) { uint64 MessagesManager::save_update_scope_notification_settings_on_server_logevent(NotificationSettingsScope scope) {
UpdateScopeNotificationSettingsOnServerLogEvent logevent{scope}; UpdateScopeNotificationSettingsOnServerLogEvent logevent{scope};
auto storer = LogEventStorerImpl<UpdateScopeNotificationSettingsOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::update_scope_notification_settings_on_server(NotificationSettingsScope scope, void MessagesManager::update_scope_notification_settings_on_server(NotificationSettingsScope scope,
@ -18985,8 +18982,8 @@ class MessagesManager::ResetAllNotificationSettingsOnServerLogEvent {
uint64 MessagesManager::save_reset_all_notification_settings_on_server_logevent() { uint64 MessagesManager::save_reset_all_notification_settings_on_server_logevent() {
ResetAllNotificationSettingsOnServerLogEvent logevent; ResetAllNotificationSettingsOnServerLogEvent logevent;
auto storer = LogEventStorerImpl<ResetAllNotificationSettingsOnServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ResetAllNotificationSettingsOnServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ResetAllNotificationSettingsOnServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_id) { void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_id) {
@ -19236,7 +19233,7 @@ void MessagesManager::read_history_on_server(Dialog *d, MessageId max_message_id
ReadHistoryInSecretChatLogEvent logevent; ReadHistoryInSecretChatLogEvent logevent;
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
logevent.max_date_ = m->date; logevent.max_date_ = m->date;
add_log_event(d->read_history_logevent_ids[0], LogEventStorerImpl<ReadHistoryInSecretChatLogEvent>(logevent), add_log_event(d->read_history_logevent_ids[0], get_log_event_storer(logevent),
LogEvent::HandlerType::ReadHistoryInSecretChat, "read history"); LogEvent::HandlerType::ReadHistoryInSecretChat, "read history");
d->last_read_inbox_message_date = m->date; d->last_read_inbox_message_date = m->date;
@ -19244,7 +19241,7 @@ void MessagesManager::read_history_on_server(Dialog *d, MessageId max_message_id
ReadHistoryOnServerLogEvent logevent; ReadHistoryOnServerLogEvent logevent;
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
logevent.max_message_id_ = max_message_id; logevent.max_message_id_ = max_message_id;
add_log_event(d->read_history_logevent_ids[0], LogEventStorerImpl<ReadHistoryOnServerLogEvent>(logevent), add_log_event(d->read_history_logevent_ids[0], get_log_event_storer(logevent),
LogEvent::HandlerType::ReadHistoryOnServer, "read history"); LogEvent::HandlerType::ReadHistoryOnServer, "read history");
} }
@ -19274,8 +19271,7 @@ void MessagesManager::read_message_thread_history_on_server(Dialog *d, MessageId
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
logevent.top_thread_message_id_ = top_thread_message_id; logevent.top_thread_message_id_ = top_thread_message_id;
logevent.max_message_id_ = max_message_id; logevent.max_message_id_ = max_message_id;
add_log_event(d->read_history_logevent_ids[top_thread_message_id.get()], add_log_event(d->read_history_logevent_ids[top_thread_message_id.get()], get_log_event_storer(logevent),
LogEventStorerImpl<ReadMessageThreadHistoryOnServerLogEvent>(logevent),
LogEvent::HandlerType::ReadMessageThreadHistoryOnServer, "read history"); LogEvent::HandlerType::ReadMessageThreadHistoryOnServer, "read history");
} }
@ -22168,9 +22164,9 @@ void MessagesManager::save_send_message_logevent(DialogId dialog_id, const Messa
CHECK(m != nullptr); CHECK(m != nullptr);
LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog"; LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog";
auto logevent = SendMessageLogEvent(dialog_id, m); auto logevent = SendMessageLogEvent(dialog_id, m);
auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, storer); m->send_message_logevent_id =
binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, get_log_event_storer(logevent));
} }
void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vector<int> bad_parts) { void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vector<int> bad_parts) {
@ -22844,10 +22840,9 @@ void MessagesManager::save_send_bot_start_message_logevent(UserId bot_user_id, D
logevent.dialog_id = dialog_id; logevent.dialog_id = dialog_id;
logevent.parameter = parameter; logevent.parameter = parameter;
logevent.m_in = m; logevent.m_in = m;
auto storer = LogEventStorerImpl<SendBotStartMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = m->send_message_logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage,
binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage, storer); get_log_event_storer(logevent));
} }
void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string &parameter, void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string &parameter,
@ -22984,10 +22979,9 @@ void MessagesManager::save_send_inline_query_result_message_logevent(DialogId di
logevent.query_id = query_id; logevent.query_id = query_id;
logevent.result_id = result_id; logevent.result_id = result_id;
logevent.m_in = m; logevent.m_in = m;
auto storer = LogEventStorerImpl<SendInlineQueryResultMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id == 0); CHECK(m->send_message_logevent_id == 0);
m->send_message_logevent_id = m->send_message_logevent_id = binlog_add(
binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, storer); G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, get_log_event_storer(logevent));
} }
void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, const Message *m, int64 query_id, void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, const Message *m, int64 query_id,
@ -24317,8 +24311,7 @@ uint64 MessagesManager::save_forward_messages_logevent(DialogId to_dialog_id, Di
const vector<Message *> &messages, const vector<Message *> &messages,
const vector<MessageId> &message_ids) { const vector<MessageId> &message_ids) {
ForwardMessagesLogEvent logevent{to_dialog_id, from_dialog_id, message_ids, messages, Auto()}; ForwardMessagesLogEvent logevent{to_dialog_id, from_dialog_id, message_ids, messages, Auto()};
auto storer = LogEventStorerImpl<ForwardMessagesLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, get_log_event_storer(logevent));
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, storer);
} }
void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_dialog_id, void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_dialog_id,
@ -24852,8 +24845,8 @@ uint64 MessagesManager::save_send_screenshot_taken_notification_message_logevent
SendScreenshotTakenNotificationMessageLogEvent logevent; SendScreenshotTakenNotificationMessageLogEvent logevent;
logevent.dialog_id = dialog_id; logevent.dialog_id = dialog_id;
logevent.m_in = m; logevent.m_in = m;
auto storer = LogEventStorerImpl<SendScreenshotTakenNotificationMessageLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendScreenshotTakenNotificationMessage,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendScreenshotTakenNotificationMessage, storer); get_log_event_storer(logevent));
} }
void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dialog_id, const Message *m, void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dialog_id, const Message *m,
@ -26880,9 +26873,9 @@ void MessagesManager::on_send_message_file_part_missing(int64 random_id, int bad
add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id); add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id);
auto logevent = SendMessageLogEvent(dialog_id, m); auto logevent = SendMessageLogEvent(dialog_id, m);
auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id != 0); CHECK(m->send_message_logevent_id != 0);
binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage, storer); binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage,
get_log_event_storer(logevent));
} }
do_send_message(dialog_id, m, {bad_part}); do_send_message(dialog_id, m, {bad_part});
@ -26932,9 +26925,9 @@ void MessagesManager::on_send_message_file_reference_error(int64 random_id) {
add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id); add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id);
auto logevent = SendMessageLogEvent(dialog_id, m); auto logevent = SendMessageLogEvent(dialog_id, m);
auto storer = LogEventStorerImpl<SendMessageLogEvent>(logevent);
CHECK(m->send_message_logevent_id != 0); CHECK(m->send_message_logevent_id != 0);
binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage, storer); binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage,
get_log_event_storer(logevent));
} }
do_send_message(dialog_id, m, {-1}); do_send_message(dialog_id, m, {-1});
@ -28084,8 +28077,8 @@ class MessagesManager::GetDialogFromServerLogEvent {
uint64 MessagesManager::save_get_dialog_from_server_logevent(DialogId dialog_id) { uint64 MessagesManager::save_get_dialog_from_server_logevent(DialogId dialog_id) {
GetDialogFromServerLogEvent logevent{dialog_id}; GetDialogFromServerLogEvent logevent{dialog_id};
auto storer = LogEventStorerImpl<GetDialogFromServerLogEvent>(logevent); return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetDialogFromServer,
return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetDialogFromServer, storer); get_log_event_storer(logevent));
} }
void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id) { void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise<Unit> &&promise, uint64 logevent_id) {
@ -28716,7 +28709,7 @@ void MessagesManager::set_dialog_folder_id_on_server(DialogId dialog_id, bool fr
SetDialogFolderIdOnServerLogEvent logevent; SetDialogFolderIdOnServerLogEvent logevent;
logevent.dialog_id_ = dialog_id; logevent.dialog_id_ = dialog_id;
logevent.folder_id_ = d->folder_id; logevent.folder_id_ = d->folder_id;
add_log_event(d->set_folder_id_logevent_id, LogEventStorerImpl<SetDialogFolderIdOnServerLogEvent>(logevent), add_log_event(d->set_folder_id_logevent_id, get_log_event_storer(logevent),
LogEvent::HandlerType::SetDialogFolderIdOnServer, "set chat folder"); LogEvent::HandlerType::SetDialogFolderIdOnServer, "set chat folder");
} }
@ -31066,8 +31059,8 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo
if (!logevent.file_ids_.empty()) { if (!logevent.file_ids_.empty()) {
auto logevent_id = logevent.id_; auto logevent_id = logevent.id_;
if (logevent_id == 0) { if (logevent_id == 0) {
auto storer = LogEventStorerImpl<DeleteMessageLogEvent>(logevent); logevent_id =
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, get_log_event_storer(logevent));
} }
MultiPromiseActorSafe mpas{"DeleteMessageMultiPromiseActor"}; MultiPromiseActorSafe mpas{"DeleteMessageMultiPromiseActor"};
@ -33323,8 +33316,8 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool
CHECK(input_channel->get_id() == telegram_api::inputChannel::ID); CHECK(input_channel->get_id() == telegram_api::inputChannel::ID);
auto access_hash = static_cast<const telegram_api::inputChannel &>(*input_channel).access_hash_; auto access_hash = static_cast<const telegram_api::inputChannel &>(*input_channel).access_hash_;
auto logevent = GetChannelDifferenceLogEvent(channel_id, access_hash); auto logevent = GetChannelDifferenceLogEvent(channel_id, access_hash);
auto storer = LogEventStorerImpl<GetChannelDifferenceLogEvent>(logevent); auto logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference,
auto logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference, storer); get_log_event_storer(logevent));
get_channel_difference_to_logevent_id_.emplace(dialog_id, logevent_id); get_channel_difference_to_logevent_id_.emplace(dialog_id, logevent_id);
} }

View File

@ -3612,8 +3612,8 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess
dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, sender_name, dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, sender_name,
date, is_from_scheduled, contains_mention, initial_is_silent, loc_key, arg, date, is_from_scheduled, contains_mention, initial_is_silent, loc_key, arg,
photo, document, notification_id}; photo, document, notification_id};
auto storer = LogEventStorerImpl<AddMessagePushNotificationLogEvent>(logevent); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification,
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, storer); get_log_event_storer(logevent));
} }
auto group_id = info.group_id; auto group_id = info.group_id;
@ -3740,7 +3740,7 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes
if (logevent_id == 0 && G()->parameters().use_message_db) { if (logevent_id == 0 && G()->parameters().use_message_db) {
EditMessagePushNotificationLogEvent logevent{dialog_id, message_id, edit_date, loc_key, arg, photo, document}; EditMessagePushNotificationLogEvent logevent{dialog_id, message_id, edit_date, loc_key, arg, photo, document};
auto storer = LogEventStorerImpl<EditMessagePushNotificationLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
auto &cur_logevent_id = temporary_edit_notification_logevent_ids_[notification_id]; auto &cur_logevent_id = temporary_edit_notification_logevent_ids_[notification_id];
if (cur_logevent_id == 0) { if (cur_logevent_id == 0) {
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::EditMessagePushNotification, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::EditMessagePushNotification, storer);

View File

@ -767,7 +767,7 @@ void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_
logevent.poll_id_ = poll_id; logevent.poll_id_ = poll_id;
logevent.full_message_id_ = full_message_id; logevent.full_message_id_ = full_message_id;
logevent.options_ = options; logevent.options_ = options;
auto storer = LogEventStorerImpl<SetPollAnswerLogEvent>(logevent); auto storer = get_log_event_storer(logevent);
if (pending_answer.generation_ == 0) { if (pending_answer.generation_ == 0) {
CHECK(pending_answer.logevent_id_ == 0); CHECK(pending_answer.logevent_id_ == 0);
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetPollAnswer, storer); logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetPollAnswer, storer);
@ -1108,8 +1108,8 @@ void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, un
LOG(INFO) << "Stop " << poll_id << " from " << full_message_id; LOG(INFO) << "Stop " << poll_id << " from " << full_message_id;
if (logevent_id == 0 && G()->parameters().use_message_db && reply_markup == nullptr) { if (logevent_id == 0 && G()->parameters().use_message_db && reply_markup == nullptr) {
StopPollLogEvent logevent{poll_id, full_message_id}; StopPollLogEvent logevent{poll_id, full_message_id};
auto storer = LogEventStorerImpl<StopPollLogEvent>(logevent); logevent_id =
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, storer); binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, get_log_event_storer(logevent));
} }
bool is_inserted = being_closed_polls_.insert(poll_id).second; bool is_inserted = being_closed_polls_.insert(poll_id).second;

View File

@ -1505,7 +1505,7 @@ void WebPagesManager::save_web_page(const WebPage *web_page, WebPageId web_page_
CHECK(web_page != nullptr); CHECK(web_page != nullptr);
if (!from_binlog) { if (!from_binlog) {
WebPageLogEvent logevent(web_page_id, web_page); WebPageLogEvent logevent(web_page_id, web_page);
LogEventStorerImpl<WebPageLogEvent> storer(logevent); auto storer = get_log_event_storer(logevent);
if (web_page->logevent_id == 0) { if (web_page->logevent_id == 0) {
web_page->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer); web_page->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer);
} else { } else {

View File

@ -232,24 +232,6 @@ class LogEventStorerUnsafe : public WithContext<TlStorerUnsafe, Global *> {
} }
}; };
} // namespace logevent
using LogEvent = logevent::LogEvent;
using LogEventParser = logevent::LogEventParser;
using LogEventStorerCalcLength = logevent::LogEventStorerCalcLength;
using LogEventStorerUnsafe = logevent::LogEventStorerUnsafe;
template <class T>
Status log_event_parse(T &data, Slice slice) TD_WARN_UNUSED_RESULT;
template <class T>
Status log_event_parse(T &data, Slice slice) {
LogEventParser parser(slice);
parse(data, parser);
parser.fetch_end();
return parser.get_status();
}
template <class T> template <class T>
class LogEventStorerImpl : public Storer { class LogEventStorerImpl : public Storer {
public: public:
@ -275,6 +257,24 @@ class LogEventStorerImpl : public Storer {
const T &event_; const T &event_;
}; };
} // namespace logevent
using LogEvent = logevent::LogEvent;
using LogEventParser = logevent::LogEventParser;
using LogEventStorerCalcLength = logevent::LogEventStorerCalcLength;
using LogEventStorerUnsafe = logevent::LogEventStorerUnsafe;
template <class T>
Status log_event_parse(T &data, Slice slice) TD_WARN_UNUSED_RESULT;
template <class T>
Status log_event_parse(T &data, Slice slice) {
LogEventParser parser(slice);
parse(data, parser);
parser.fetch_end();
return parser.get_status();
}
template <class T> template <class T>
BufferSlice log_event_store(const T &data) { BufferSlice log_event_store(const T &data) {
LogEventStorerCalcLength storer_calc_length; LogEventStorerCalcLength storer_calc_length;
@ -294,4 +294,9 @@ BufferSlice log_event_store(const T &data) {
return value_buffer; return value_buffer;
} }
template <class T>
logevent::LogEventStorerImpl<T> get_log_event_storer(const T &event) {
return logevent::LogEventStorerImpl<T>(event);
}
} // namespace td } // namespace td