Page MenuHomePhabricator

D11172.diff
No OneTemporary

D11172.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h
--- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h
@@ -103,6 +103,10 @@
const std::vector<ClientMessageToDevice> &messages) const = 0;
virtual std::vector<ClientMessageToDevice>
getAllMessagesToDevice(const std::string &deviceID) const = 0;
+ virtual void removeMessagesToDeviceOlderThan(
+ const ClientMessageToDevice &lastConfirmedMessage) const = 0;
+ virtual void
+ removeAllMessagesForDevice(const std::string &deviceID) const = 0;
#ifdef EMSCRIPTEN
virtual std::vector<WebThread> getAllThreadsWeb() const = 0;
diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
@@ -116,6 +116,9 @@
const std::vector<ClientMessageToDevice> &messages) const override;
std::vector<ClientMessageToDevice>
getAllMessagesToDevice(const std::string &deviceID) const override;
+ void removeMessagesToDeviceOlderThan(
+ const ClientMessageToDevice &lastConfirmedMessage) const override;
+ void removeAllMessagesForDevice(const std::string &deviceID) const override;
#ifdef EMSCRIPTEN
std::vector<WebThread> getAllThreadsWeb() const override;
diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
@@ -1731,6 +1731,47 @@
return messages;
}
+
+void SQLiteQueryExecutor::removeMessagesToDeviceOlderThan(
+ const ClientMessageToDevice &lastConfirmedMessageClient) const {
+ static std::string query =
+ "DELETE FROM messages_to_device "
+ "WHERE timestamp <= ? AND device_id IN (?);";
+
+ MessageToDevice lastConfirmedMessage =
+ lastConfirmedMessageClient.toMessageToDevice();
+
+ comm::SQLiteStatementWrapper preparedSQL(
+ SQLiteQueryExecutor::getConnection(),
+ query,
+ "Failed to remove messages to device");
+
+ sqlite3_bind_int64(preparedSQL, 1, lastConfirmedMessage.timestamp);
+ sqlite3_bind_text(
+ preparedSQL,
+ 2,
+ lastConfirmedMessage.device_id.c_str(),
+ -1,
+ SQLITE_TRANSIENT);
+
+ int result = sqlite3_step(preparedSQL);
+ if (result != SQLITE_DONE) {
+ throw std::runtime_error(
+ "Failed to execute removeMessagesToDeviceOlderThan statement: " +
+ std::string(sqlite3_errmsg(SQLiteQueryExecutor::getConnection())));
+ }
+}
+
+void SQLiteQueryExecutor::removeAllMessagesForDevice(
+ const std::string &deviceID) const {
+ static std::string removeMessagesSQL =
+ "DELETE FROM messages_to_device "
+ "WHERE device_id IN (?);";
+ std::vector<std::string> keys = {deviceID};
+ removeEntitiesByKeys(
+ SQLiteQueryExecutor::getConnection(), removeMessagesSQL, keys);
+}
+
#ifdef EMSCRIPTEN
std::vector<WebThread> SQLiteQueryExecutor::getAllThreadsWeb() const {
auto threads = this->getAllThreads();
diff --git a/web/database/_generated/comm_query_executor.wasm b/web/database/_generated/comm_query_executor.wasm
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 1, 7:25 PM (21 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2400566
Default Alt Text
D11172.diff (3 KB)

Event Timeline