-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mediator) : Add TTL for message collection (#290)
Add TTL for message collection to do house keeping update time stamp field from String to Intant Update initdb.js Add migration script for ttl Signed-off-by: Shailesh Patil <53746241+mineme0110@users.noreply.github.com>
- Loading branch information
1 parent
0bd5259
commit 8691d99
Showing
8 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
) |