Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3368593
D12074.id40595.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D12074.id40595.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
@@ -140,7 +140,8 @@
virtual std::vector<OutboundP2PMessage>
getAllOutboundP2PMessages(const std::string &deviceID) const = 0;
virtual void removeOutboundP2PMessagesOlderThan(
- const OutboundP2PMessage &lastConfirmedMessage) const = 0;
+ std::string lastConfirmedMessageID,
+ std::string deviceID) const = 0;
virtual void
removeAllOutboundP2PMessages(const std::string &deviceID) const = 0;
virtual void setCiphertextForOutboundP2PMessage(
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
@@ -150,7 +150,8 @@
std::vector<OutboundP2PMessage>
getAllOutboundP2PMessages(const std::string &deviceID) const override;
void removeOutboundP2PMessagesOlderThan(
- const OutboundP2PMessage &lastConfirmedMessage) const override;
+ std::string lastConfirmedMessageID,
+ std::string deviceID) const override;
void removeAllOutboundP2PMessages(const std::string &deviceID) const override;
void setCiphertextForOutboundP2PMessage(
std::string messageID,
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
@@ -2141,33 +2141,26 @@
}
void SQLiteQueryExecutor::removeOutboundP2PMessagesOlderThan(
- const OutboundP2PMessage &lastConfirmedMessageClient) const {
- static std::string query =
+ std::string lastConfirmedMessageID,
+ std::string deviceID) const {
+ std::string query =
"DELETE FROM outbound_p2p_messages "
- "WHERE timestamp <= ? AND device_id IN (?);";
-
- SQLiteOutboundP2PMessage lastConfirmedMessage =
- lastConfirmedMessageClient.toSQLiteOutboundP2PMessage();
+ "WHERE timestamp <= ("
+ " SELECT timestamp "
+ " FROM outbound_p2p_messages"
+ " WHERE message_id = ?"
+ ") "
+ "AND device_id IN (?);";
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);
+ bindStringToSQL(lastConfirmedMessageID.c_str(), preparedSQL, 1);
+ bindStringToSQL(deviceID.c_str(), preparedSQL, 2);
- int result = sqlite3_step(preparedSQL);
- if (result != SQLITE_DONE) {
- throw std::runtime_error(
- "Failed to execute removeOutboundP2PMessagesOlderThan statement: " +
- std::string(sqlite3_errmsg(SQLiteQueryExecutor::getConnection())));
- }
+ sqlite3_step(preparedSQL);
}
void SQLiteQueryExecutor::removeAllOutboundP2PMessages(
diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
literal 0
Hc$@<O00001
diff --git a/web/shared-worker/queries/outbound-p2p-message-queries.test.js b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
--- a/web/shared-worker/queries/outbound-p2p-message-queries.test.js
+++ b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
@@ -100,12 +100,19 @@
});
it('should remove when there is only one message', () => {
- queryExecutor?.removeOutboundP2PMessagesOlderThan(TEST_MSG_2);
+ queryExecutor?.removeOutboundP2PMessagesOlderThan(
+ TEST_MSG_2.messageID,
+ TEST_MSG_2.deviceID,
+ );
+
expect(queryExecutor?.getAllOutboundP2PMessages(device2).length).toBe(0);
});
it('should remove older messages', () => {
- queryExecutor?.removeOutboundP2PMessagesOlderThan(TEST_MSG_1);
+ queryExecutor?.removeOutboundP2PMessagesOlderThan(
+ TEST_MSG_1.messageID,
+ TEST_MSG_1.deviceID,
+ );
expect(queryExecutor?.getAllOutboundP2PMessages(device1)).toStrictEqual([
TEST_MSG_4,
]);
diff --git a/web/shared-worker/types/sqlite-query-executor.js b/web/shared-worker/types/sqlite-query-executor.js
--- a/web/shared-worker/types/sqlite-query-executor.js
+++ b/web/shared-worker/types/sqlite-query-executor.js
@@ -159,7 +159,8 @@
addOutboundP2PMessages(messages: $ReadOnlyArray<OutboundP2PMessage>): void;
removeOutboundP2PMessagesOlderThan(
- lastConfirmedMessage: OutboundP2PMessage,
+ lastConfirmedMessageID: string,
+ deviceID: string,
): void;
removeAllOutboundP2PMessages(deviceID: string): void;
getAllOutboundP2PMessages(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 8:21 PM (21 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2586076
Default Alt Text
D12074.id40595.diff (5 KB)
Attached To
Mode
D12074: [SQLite] remove Outbound P2P messages based on `messageID` and `deviceID`
Attached
Detach File
Event Timeline
Log In to Comment