Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3526018
D11172.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11172.id.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 7:12 PM (8 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700864
Default Alt Text
D11172.id.diff (3 KB)
Attached To
Mode
D11172: [SQLite] implement removing `MessageToDevice` items
Attached
Detach File
Event Timeline
Log In to Comment