diff options
author | Trumeet <yuuta@yuuta.moe> | 2023-03-19 17:04:21 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2023-03-19 17:04:21 -0700 |
commit | 261d0f23f25151068c58db88c447289a882b4a6e (patch) | |
tree | 04587186ec0df7020775b58d33c75f7d8841b84d /store.c | |
parent | 92829eb1abde84916d92b22e107fc3ae7dc4bad2 (diff) | |
download | ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar.gz ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.tar.bz2 ksyxbot-261d0f23f25151068c58db88c447289a882b4a6e.zip |
Use message index instead of URL to save space
Refresh code is not maintained.
Diffstat (limited to 'store.c')
-rw-r--r-- | store.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -6,12 +6,14 @@ #include "logic.h" #include "db.h" #include "botd.h" +#include "utils.h" #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <assert.h> +#include <stdint.h> /* Temp object between message callback and link callback */ struct say { @@ -33,9 +35,10 @@ static void cb_link(bool successful, struct TdObject *result, struct TdError *er LOGDV("%s", s->text); struct TdMessageLink *link = (struct TdMessageLink *) result; int r; + uint32_t msg_index = tg_url_get_index(link->link_); sqlite3_stmt *stmt = NULL; if ((r = sqlite3_prepare_v2(db, - "INSERT INTO says(t, url, msg) VALUES(?, ?, ?)", + "INSERT INTO says(t, msg_index, msg) VALUES(?, ?, ?)", -1, &stmt, NULL))) { @@ -48,8 +51,14 @@ static void cb_link(bool successful, struct TdObject *result, struct TdError *er if ((r = sqlite3_bind_text(stmt, 1, s->text, (int) strlen(s->text), NULL))) { goto sql_err; } - if ((r = sqlite3_bind_text(stmt, 2, link->link_, (int) strlen(link->link_), NULL))) { - goto sql_err; + if (msg_index) { + if ((r = sqlite3_bind_int64(stmt, 2, msg_index))) { + goto sql_err; + } + } else { + if ((r = sqlite3_bind_null(stmt, 2))) { + goto sql_err; + } } if ((r = sqlite3_bind_int64(stmt, 3, s->msg_id))) { goto sql_err; |