Best Practice - Multiple Publications Same Collection


#1

Dear Community,

I have reached another best practice question with this complexe (for me) publication / subscription issue. It’s not gonna be about code but about how to make the best out of meteor. For the problem please consider a facebook clone with a main difference :

  • some posts can be private :

    • you need to be a subscribed paid user for each user you follow
    • or you need to can pay private post one by on to see them
    • For the private post where not paid I want to publish only part of data (title but no content)
  • Rest is more classic :

    • I want a feed of the posts I follow
    • I want a searchbar where all public post can be searched through

So here I am with my main page that as a searchbar on top and a Feed in the middle.

I need the Feed to show :

  • Public post from author I am following
  • Private single post I paid for wether I am following the author or not
  • Private post from authors I am following with limited data if I did not pay
  • Private post with all data for authors I follow and I paid
  • My own posts

I need the Feed NOT to show :

  • Public post from authors I am not following

I need the searchBar to look through :

  • All public posts
  • Private single post I paid for wether I am following the author or not
  • Private post from authors I am following with limited data if I did not pay

I need the SearchBar NOT to shox:

  • Unpaid or unsubscribed private post with limited data

What I did:

I created the following publications :

  • Public post from author I am following (pub 1)
  • Private single post I paid for wether I am following the author or not (pub 2)
  • Private post from authors I am following with limited data if I did not pay (pub 3)
  • Private call post from authors I am following and paid with full data (pub 4)
  • All public posts (pub 5)
  • My own posts (pub 6)

In my Feed, I subscribe to pub 1, 2, 3, 4 and 5
In the searchBar to pub 2,4,5

As I subscribe to both in the same parent component (two different children component) then I have to make all the filter on client side as well to prevent :

  • Non subscribed public post to be seen in the feed
  • Private post to be seen in search bar

There you go, I have 6 publications and 8 subscriptions from the same collections.

  • I need to subscribe to a “Subscriptions” collection which store :
    follower_id following_id paid (boolean)

And I have to call this Subscriptions on both client and server to make sure my feed only shows the good post.

it seems like a hell lot to me. I am pretty sure I am not optimizing this and I am scared about ressources if the number of post increases too fase.

Please for those who read until here, do you think my solution is the best ?

Shall I try to group publications on server side ? (and Can I make one publication from the same collections where some post will send all the data and some post only some fields ??)

Any way to seaparate more the Search and the Feed component so that I don’t have to make again all the filters on client side as I am subscribing to same collection?

Also last questions : is there a way to manage a searchBar, a reactive one that shows live result, searching through all past post, without having to be full time subscribed to all theses post from server side (what If there is 1000 posts, 20 000 post ?

i could not thank enough someone who could help me clarify this situation.

Regards


#2

No one to help or clarify the best practice ?


#3

So let’s say you have tens of thousands of posts available. I would lean towards not having any subs at all in this application you describe. Do you really need a “Live” feed, or is it enough to get the most recent ones for your feed, and then check if any new have appeared every minute or so? Who cares if the posts are not absolutely updated to the last second.

For search, I would NOT subscribe to the search result, but instead called a search method that returned the most relevant results on input into the search bar.


#4

So to make sure I understand :

you’d manage both the feed and the search with Method, called at componentDidMount for the feed, and onChange input for the Search that would return a list of posts ?

In this case you’d not have to use any withTracker method BUT on the other hand for the feed a refresh (manuel or automatic with a setTimeout) would be needed ? You’re method would send the posts as props to a component that render them ?

I like this idea very much for the Search anyway, will see if required for feed or not (there I just send last posts anyway with infinite scrolling)

Thanks for the tip already !


#5

I would save the search results to state, and render from state.

Or you could have a “Get latest posts” button, like twitter has. It checks every minute or so the count of new posts, and allow you to refresh the list of tweets with a button.

You could save the posts in local react state, and render from there, or in the state of a component that only loads the data and sends it as props from that component’s state, or use something like redux.