Remove non-const WebPagesManager::get_web_page.

GitOrigin-RevId: 87352c2c4f21142ae18ce163e2a84bd3939e09f8
This commit is contained in:
levlam 2019-01-21 23:55:26 +03:00
parent 36d45046d0
commit 73d09e1816
2 changed files with 14 additions and 24 deletions

View File

@ -190,7 +190,7 @@ class WebPagesManager::WebPage {
FileId document_file_id; FileId document_file_id;
WebPageInstantView instant_view; WebPageInstantView instant_view;
uint64 logevent_id = 0; mutable uint64 logevent_id = 0;
template <class T> template <class T>
void store(T &storer) const { void store(T &storer) const {
@ -1771,7 +1771,7 @@ WebPageId WebPagesManager::get_web_page_instant_view(const string &url, bool for
WebPageId WebPagesManager::get_web_page_instant_view(WebPageId web_page_id, bool force_full, Promise<Unit> &&promise) { WebPageId WebPagesManager::get_web_page_instant_view(WebPageId web_page_id, bool force_full, Promise<Unit> &&promise) {
LOG(INFO) << "Trying to get web page instant view for " << web_page_id; LOG(INFO) << "Trying to get web page instant view for " << web_page_id;
auto web_page_instant_view = get_web_page_instant_view(web_page_id); const auto *web_page_instant_view = get_web_page_instant_view(web_page_id);
if (web_page_instant_view == nullptr) { if (web_page_instant_view == nullptr) {
promise.set_value(Unit()); promise.set_value(Unit());
return WebPageId(); return WebPageId();
@ -2138,15 +2138,6 @@ void WebPagesManager::update_messages_content(WebPageId web_page_id, bool have_w
pending_web_pages_timeout_.cancel_timeout(web_page_id.get()); pending_web_pages_timeout_.cancel_timeout(web_page_id.get());
} }
WebPagesManager::WebPage *WebPagesManager::get_web_page(WebPageId web_page_id) {
auto p = web_pages_.find(web_page_id);
if (p == web_pages_.end()) {
return nullptr;
} else {
return p->second.get();
}
}
const WebPagesManager::WebPage *WebPagesManager::get_web_page(WebPageId web_page_id) const { const WebPagesManager::WebPage *WebPagesManager::get_web_page(WebPageId web_page_id) const {
auto p = web_pages_.find(web_page_id); auto p = web_pages_.find(web_page_id);
if (p == web_pages_.end()) { if (p == web_pages_.end()) {
@ -2157,11 +2148,12 @@ const WebPagesManager::WebPage *WebPagesManager::get_web_page(WebPageId web_page
} }
WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant_view(WebPageId web_page_id) { WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant_view(WebPageId web_page_id) {
auto web_page = get_web_page(web_page_id); auto p = web_pages_.find(web_page_id);
if (web_page == nullptr || web_page->instant_view.is_empty) { if (p == web_pages_.end() || p->second->instant_view.is_empty) {
return nullptr; return nullptr;
} else {
return &p->second->instant_view;
} }
return &web_page->instant_view;
} }
const WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant_view(WebPageId web_page_id) const { const WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant_view(WebPageId web_page_id) const {
@ -2643,7 +2635,7 @@ class WebPagesManager::WebPageLogEvent {
} }
}; };
void WebPagesManager::save_web_page(WebPage *web_page, WebPageId web_page_id, bool from_binlog) { void WebPagesManager::save_web_page(const WebPage *web_page, WebPageId web_page_id, bool from_binlog) {
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
return; return;
} }
@ -2696,7 +2688,7 @@ string WebPagesManager::get_web_page_database_key(WebPageId web_page_id) {
} }
void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool success) { void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool success) {
WebPage *web_page = get_web_page(web_page_id); auto web_page = get_web_page(web_page_id);
if (web_page == nullptr) { if (web_page == nullptr) {
LOG(ERROR) << "Can't find " << (success ? "saved " : "failed to save ") << web_page_id; LOG(ERROR) << "Can't find " << (success ? "saved " : "failed to save ") << web_page_id;
return; return;
@ -2750,8 +2742,7 @@ void WebPagesManager::on_load_web_page_from_database(WebPageId web_page_id, stri
// G()->td_db()->get_sqlite_pmc()->erase(get_web_page_database_key(web_page_id), Auto()); // G()->td_db()->get_sqlite_pmc()->erase(get_web_page_database_key(web_page_id), Auto());
// return; // return;
WebPage *web_page = get_web_page(web_page_id); if (!have_web_page(web_page_id)) {
if (web_page == nullptr) {
if (!value.empty()) { if (!value.empty()) {
auto result = make_unique<WebPage>(); auto result = make_unique<WebPage>();
auto status = log_event_parse(*result, value); auto status = log_event_parse(*result, value);
@ -2773,8 +2764,8 @@ bool WebPagesManager::have_web_page_force(WebPageId web_page_id) {
return get_web_page_force(web_page_id) != nullptr; return get_web_page_force(web_page_id) != nullptr;
} }
WebPagesManager::WebPage *WebPagesManager::get_web_page_force(WebPageId web_page_id) { const WebPagesManager::WebPage *WebPagesManager::get_web_page_force(WebPageId web_page_id) {
WebPage *web_page = get_web_page(web_page_id); auto web_page = get_web_page(web_page_id);
if (web_page != nullptr) { if (web_page != nullptr) {
return web_page; return web_page;
} }
@ -2792,7 +2783,7 @@ WebPagesManager::WebPage *WebPagesManager::get_web_page_force(WebPageId web_page
} }
string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const { string WebPagesManager::get_web_page_search_text(WebPageId web_page_id) const {
auto *web_page = get_web_page(web_page_id); auto web_page = get_web_page(web_page_id);
if (web_page == nullptr) { if (web_page == nullptr) {
return ""; return "";
} }

View File

@ -142,7 +142,6 @@ class WebPagesManager : public Actor {
void update_messages_content(WebPageId web_page_id, bool have_web_page); void update_messages_content(WebPageId web_page_id, bool have_web_page);
WebPage *get_web_page(WebPageId web_page_id);
const WebPage *get_web_page(WebPageId web_page_id) const; const WebPage *get_web_page(WebPageId web_page_id) const;
WebPageInstantView *get_web_page_instant_view(WebPageId web_page_id); WebPageInstantView *get_web_page_instant_view(WebPageId web_page_id);
@ -186,7 +185,7 @@ class WebPagesManager : public Actor {
void on_get_web_page_instant_view(WebPage *web_page, tl_object_ptr<telegram_api::Page> &&page_ptr, int32 hash, void on_get_web_page_instant_view(WebPage *web_page, tl_object_ptr<telegram_api::Page> &&page_ptr, int32 hash,
DialogId owner_dialog_id); DialogId owner_dialog_id);
void save_web_page(WebPage *web_page, WebPageId web_page_id, bool from_binlog); void save_web_page(const WebPage *web_page, WebPageId web_page_id, bool from_binlog);
static string get_web_page_database_key(WebPageId web_page_id); static string get_web_page_database_key(WebPageId web_page_id);
@ -196,7 +195,7 @@ class WebPagesManager : public Actor {
void on_load_web_page_from_database(WebPageId web_page_id, string value); void on_load_web_page_from_database(WebPageId web_page_id, string value);
WebPage *get_web_page_force(WebPageId web_page_id); const WebPage *get_web_page_force(WebPageId web_page_id);
static string get_web_page_instant_view_database_key(WebPageId web_page_id); static string get_web_page_instant_view_database_key(WebPageId web_page_id);