Page MenuHomePhabricator

D4220.id13868.diff
No OneTemporary

D4220.id13868.diff

diff --git a/services/tunnelbroker/src/Database/DatabaseManager.h b/services/tunnelbroker/src/Database/DatabaseManager.h
--- a/services/tunnelbroker/src/Database/DatabaseManager.h
+++ b/services/tunnelbroker/src/Database/DatabaseManager.h
@@ -47,6 +47,9 @@
std::vector<std::shared_ptr<MessageItem>>
findMessageItemsByReceiver(const std::string &toDeviceID);
void removeMessageItem(const std::string &messageID);
+ void removeMessageItemsOlderThenDeviceCheckpoint(
+ const std::string &toDeviceID,
+ const size_t &checkpointTime);
};
} // namespace database
diff --git a/services/tunnelbroker/src/Database/DatabaseManager.cpp b/services/tunnelbroker/src/Database/DatabaseManager.cpp
--- a/services/tunnelbroker/src/Database/DatabaseManager.cpp
+++ b/services/tunnelbroker/src/Database/DatabaseManager.cpp
@@ -209,6 +209,29 @@
this->innerRemoveItem(*item);
}
+void DatabaseManager::removeMessageItemsOlderThenDeviceCheckpoint(
+ const std::string &toDeviceID,
+ const size_t &checkpointTime) {
+ std::vector<std::shared_ptr<MessageItem>> messageItems =
+ this->findMessageItemsByReceiver(toDeviceID);
+ std::vector<Aws::DynamoDB::Model::WriteRequest> writeRequests;
+
+ for (std::shared_ptr<MessageItem> &messageItem : messageItems) {
+ if (messageItem->getCreatedAt() <= checkpointTime) {
+ Aws::DynamoDB::Model::DeleteRequest deleteRequest;
+ PrimaryKeyDescriptor pk = messageItem->getPrimaryKeyDescriptor();
+ PrimaryKeyValue primaryKeyValue = messageItem->getPrimaryKeyValue();
+ deleteRequest.AddKey(
+ pk.partitionKey,
+ Aws::DynamoDB::Model::AttributeValue(primaryKeyValue.partitionKey));
+ Aws::DynamoDB::Model::WriteRequest curWriteRequest;
+ curWriteRequest.SetDeleteRequest(deleteRequest);
+ writeRequests.push_back(curWriteRequest);
+ }
+ }
+ this->innerBatchWriteItem(MESSAGES_TABLE_NAME, writeRequests);
+}
+
} // namespace database
} // namespace network
} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 9, 12:10 PM (9 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2834725
Default Alt Text
D4220.id13868.diff (1 KB)

Event Timeline