8000 Merge pull request #26 from tdlight-team/getmemorystats · deus-developer/telegram-bot-api@7c642e8 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 7c642e8

Browse files
authored
Merge pull request tdlib#26 from tdlight-team/getmemorystats
Added getMemoryStats query
2 parents 0edac66 + a02597b commit 7c642e8

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ Please note that only TDLight-specific issues are suitable for this repository.
3737

3838
<a name="added-api-methods"></a>
3939
#### Added API Methods
40-
##### Method `optimize_memory`
41-
Calling `optimize_memory` will remove old data from the in-memory cache and give the freed memory back to the os
40+
##### Method `optimizeMemory`
41+
Calling `optimizeMemory` will remove old data from the in-memory cache and give the freed memory back to the os
42+
43+
##### Method `getMemoryStats`
44+
Calling `getMemoryStats` will return a json containing the info about the memory manager, more info [here](https://github.com/tdlight-team/tdlight#tdapigetmemorystatistics)
4245

4346
##### Method `getMessageInfo`
4447
Get information about a message

telegram-bot-api/Client.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ bool Client::init_methods() {
295295
methods_.emplace("deletemessages", &Client::process_delete_messages_query);
296296
methods_.emplace("togglegroupinvites", &Client::process_toggle_group_invites_query);
297297
methods_.emplace("ping", &Client::process_ping_query);
298+
methods_.emplace("getmemorystats", &Client::process_get_memory_stats_query);
298299

299300

300301
return true;
@@ -3328,6 +3329,26 @@ class Client::TdOnPingCallback : public TdQueryCallback {
33283329
PromisedQueryPtr query_;
33293330
};
33303331

3332+
class Client::TdOnGetMemoryStatisticsCallback : public TdQueryCallback {
3333+
public:
3334+
explicit TdOnGetMemoryStatisticsCallback(PromisedQueryPtr query)
3335+
: query_(std::move(query)) {
3336+
}
3337+
3338+
void on_result(object_ptr<td_api::Object> result) override {
3339+
if (result->get_id() == td_api::error::ID) {
3340+
return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
3341+
}
3342+
3343+
auto res = move_object_as<td_api::memoryStatistics>(result);
3344+
3345+
answer_query(td::JsonRaw(res->statistics_), std::move(query_));
3346+
}
3347+
3348+
private:
3349+
PromisedQueryPtr query_;
3350+
};
3351+
33313352
//end custom callbacks impl
33323353

33333354
void Client::close() {
@@ -7677,8 +7698,13 @@ td::Status Client::process_ping_query(PromisedQueryPtr &query) {
76777698
return Status::OK();
76787699
}
76797700

7701+
td::Status Client::process_get_memory_stats_query(PromisedQueryPtr &query) {
7702+
send_request(make_object<td_api::getMemoryStatistics>(),
7703+
std::make_unique<TdOnGetMemoryStatisticsCallback>(std::move(query)));
7704+
return Status::OK();
7705+
}
76807706
//end custom methods impl
7681-
//start costom auth methods impl
7707+
//start custom auth methods impl
76827708

76837709
void Client::process_authcode_query(PromisedQueryPtr &query) {
76847710
auto code = query->arg("code");

telegram-bot-api/Client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class Client : public WebhookActor::Callback {
191191

192192
//start custom callbacks
193193
class TdOnPingCallback;
194+
class TdOnGetMemoryStatisticsCallback;
194195
//end custom callbacks
195196

196197
void on_get_reply_message(int64 chat_id, object_ptr<td_api::message> reply_to_message);
@@ -508,6 +509,7 @@ class Client : public WebhookActor::Callback {
508509
Status process_delete_messages_query(PromisedQueryPtr &query);
509510
Status process_toggle_group_invites_query(PromisedQueryPtr &query);
510511
Status process_ping_query(PromisedQueryPtr &query);
512+
Status process_get_memory_stats_query(PromisedQueryPtr &query);
511513

512514
//custom auth methods
513515
void process_authcode_query(PromisedQueryPtr &query);

0 commit comments

Comments
 (0)
0