-
Notifications
You must be signed in to change notification settings - Fork 11
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
adding hash to the subscription object to avoid duplicated subscripti… #23
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 | ||
---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||
const errors = require('../util/errors'), | ||||
const crypto = require ('crypto') | ||||
const errors = require('../util/errors'), | ||||
TransactionWatcher = require('./transaction-watcher'), | ||||
Notifier = require('./notifier'), | ||||
storage = require('./storage'), | ||||
|
@@ -38,10 +39,21 @@ class Observer { | |||
} | ||||
|
||||
subscribe(subscriptionParams, user) { | ||||
//TODO: prevent duplicate subscriptions by checking subscription hash (fields "account", "asset_type" etc.) | ||||
//https://www.npmjs.com/package/farmhash | ||||
return this.loadSubscriptions() | ||||
.then(() => { | ||||
// Create hash in the subscription to avoid duplication | ||||
|
||||
let hashData = `${subscriptionParams.account} ${subscriptionParams.asset_type} ${subscriptionParams.asset_code} ${subscriptionParams.asset_issuer}` | ||||
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. Please check all meaningful subscription params here: operations-notifier/logic/storage.js Line 138 in 93aa567
We can use 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. You are welcome!
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. I did a bit more of research and found that Mongo uses 24 character hex string for its _id. The hash generated is a 32 character hex string. No idea how to use the has as the generic id 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. And about the delete endpoint I saw that the deleted subscriptions have a status of 1 👍 |
||||
let hash = crypto.createHash('md5').update(hashData).digest("hex"); | ||||
subscriptionParams.hash = hash | ||||
|
||||
let subscription = this.subscriptions.find(s => s.hash == hash) | ||||
|
||||
if(subscription){ | ||||
|
||||
return subscription | ||||
} | ||||
|
||||
if (this.getActiveSubscriptionsCount() >= config.maxActiveSubscriptions) { | ||||
return Promise.reject(errors.forbidden('Max active subscriptions exceeded.')) | ||||
} | ||||
|
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.
And please bump version in
package.json