Replies: 1 comment 1 reply
-
I am a big fan of using fastJoin to populate a document with it's children. It's fast, steady and although it took me a moment to figure it out, now I do not even know why I thought it was complex once))) As for the channel publishing, I rewrote the publish in // find what services (by name) we will publish as in our case we will not publish all
const chnAllMembers = app.get('publishChannels').allMembers // services to publish for members of account
const chnOthers = app.get('publishChannels').othersOnly // services for non-members
const chnAll =[...chnAllMembers, ...chnOthers] // all services
// Share all events from services that have an *accountId* on the account channels
// eslint-disable-next-line no-unused-vars
app.publish((data, context) => {
const path = context.path
// check if we have an account channel to publish to
if (chnAll.includes(path) && data._id && data.accountId) {
const newChn = Object.assign({}, app.channel(accountChn(data.accountId)))
if (chnOthers.includes(path) && context.params.user) {
const userId = context.params.user._id
// console.log(`>>> ${accountChn(data.accountId)} ${connections.length}`)
newChn.connections = newChn.connections.filter(connection => {
const connectionUserId = connection.user._id
return connectionUserId !== userId
})
}
if (newChn.connections.length > 0) {
console.log(`>> Publishing "${path}" events on channel "${accountChn(data.accountId)}" with ${newChn.connections.length} connections`)
}
return newChn
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, wanna check with you guys on how do you guys do parent-child ref for mongoose r/s. I know that using ref in the schema, you can do it but all the example shown are quite straight-forward like such https://mongoosejs.com/docs/populate.html
However, it isn't always the case where the parent and child are created together, and for those that do not, there would have an additional query to update the parent whenever there is a new child. So for example,
post and comments
, the user creating a post and other users creating a comment on the post itself is a separate action altogether.To further illustrate the possible scenario is where both
post
andcomment
will be published via websocket to users, so in the scenario above, we would have...Is this how usually you guys would have done it? Because each new
comment
would have been emitted to client but with that, also comes along apatched post
event to client which might be quite redundant.What is the best course of action for this kind of scenario? Could it be for this scenario, using
_patch
is better since it does not publish events?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions