-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mediator) : Add TTL for message collection #290
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,21 @@ To set up the mediator storage (MongoDB): | |
- `MONGODB_PASSWORD` - is the password used by the Mediator service to connect to the database. | ||
- `MONGODB_DB_NAME` - is the name of the database used by the Mediator. | ||
|
||
#### Mediator storage | ||
- The `messages` collection contains two types of messages: `Mediator` and `User`. | ||
1. **Mediator Messages**: | ||
- These messages received by mediator for any interactions with the mediator. | ||
- Examples include messages for setting up mediation, requesting mediation, or picking up messages from the mediator. | ||
- These messages stored in collection can be used for debugging purpose mediator functionality and interactions with the mediator. Hence they can be deleted after a period of time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- This message type `Mediator` can be setup to have a configurable Time-To-Live (TTL) value, after which they can expire. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- This is how the TTL can be configured for the collection messages [initdb.js](initdb.js) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
2. **User Messages**: | ||
- These are the actual messages e.g like the Forward message from the mediator, contain a `User` message inside. This inside message is stored as type `User` to be delivered to user. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- They do not have a TTL, and will persist in the system until the user retrieves them using a pickup protocol and deletes them. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- The mediator is responsible for storing and making these user messages available for delivery to the intended recipients. | ||
|
||
ℹ️ For existing users, please utilize the migration script [migration_mediator_collection.js](migration_mediator_collection.js) to migrate the collection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ::: info There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not valid in markdown file :::info |
||
|
||
## Run | ||
|
||
The DIDComm Mediator comprises two elements: a backend service and a database. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// migration script | ||
// Please utilize the following script to update your existing collection for Mediator release v0.14.5 and beyond. | ||
const collectionName = 'messages'; | ||
const collectionNameUserAccount = 'user.account'; | ||
let userHashes = []; | ||
|
||
db.getCollection(collectionNameUserAccount).find({}).forEach(function(user) { | ||
user.messagesRef.forEach(function(messageRef) { | ||
userHashes.push(messageRef.hash); | ||
}); | ||
}); | ||
|
||
db.getCollection('messages').find({}).forEach(function(message) { | ||
let newTimestamp = new Date(message.ts); | ||
if(userHashes.includes(message._id)) { | ||
db.getCollection('messages').updateOne({ _id: message._id }, { $set: { message_type: 'User', ts: newTimestamp } }); | ||
} else { | ||
db.getCollection('messages').updateOne({ _id: message._id }, { $set: { message_type: 'Mediator', ts: newTimestamp } }); | ||
} | ||
}); | ||
|
||
// There are 2 message types `Mediator` and `User` Please follow the Readme for more details in the section Mediator storage | ||
const expireAfterSeconds = 7 * 24 * 60 * 60; // 7 day * 24 hours * 60 minutes * 60 seconds | ||
db.getCollection(collectionMessages).createIndex( | ||
{ ts: 1 }, | ||
{ | ||
name: "message-ttl-index", | ||
partialFilterExpression: { "message_type" : "Mediator" }, | ||
expireAfterSeconds: expireAfterSeconds | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.