Page MenuHomePhabricator

D12074.id.diff
No OneTemporary

D12074.id.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
@@ -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

Mime Type
text/plain
Expires
Tue, Dec 24, 5:14 PM (8 m, 36 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700556
Default Alt Text
D12074.id.diff (5 KB)

Event Timeline