Publish composite vs publish-lookups

Hello guys, have a quick question.

Publish composite openly admits to not being the fastest kid in town but I found a new package called publish-lookups that claims to be. That’s exciting!

I’m sort of confused about a claim publish-lookups makes however.

publish-composite does not scale well, because in the second level queries it will create N cursor observers, where N is the number of documents returned in Primary query. This behavour will overload your database.

I found this interesting as I use publish-composite at the moment.

I tested the statement out by publishing a total of 26 documents with publish-composite (1 parent, 25 documents). Galaxy’s APM shows that I only created 2 observers - the same as what publish-lookups would have created.

Is publish-lookups comparing itself with an outdated version of publish-composite? Does publish-composite really create 2 observers in a case like the above?

Thanks!

1 Like

It creates a new observer for each document returned in the parent query, because when you write a query like (forgive me, I can’t remember the exact syntax used but you get the idea)

// parent query
Users.find({ team: 'Blue team' })

// child query
Hats.find({ userId: parent._id });

If your parent query returns three documents, then publish-composite is going to create three observers, like:

Hats.find({ userId: firstUser._id })
Hats.find({ userId: secondUser._id })
Hats.find({ userId: thirdUser._id })

plus the first one for Users.find().

Does that clear it up?

Ah ha!

Cleared that up for me real good. Thanks~