Global variable to avoid subscription all the time


#1

Hi all,

I am recently creating a forum which has 12 categories of articles.
each article has a popularity counts based on some factors.

The thing is, I wanna show the top 5 most popular articles for each category on the landing page.
Currently I am doing this by subscribing 5 articles with certain category and highest popular-score in the Articles collection.

but then I have to do the subscription 12 times, which is very expensive.

I wonder if there is a way in practice, that I can subscribe the articles 12 time and save them in a “Global variable”, and update every 10 mins in the background ( automatically updating without query from user ).

So when users visit landing page, I can just show the “Global variable” and avoid the waiting time from subscription. I thought about Template.registerHelper(XXXXX), but I dont know how to make it update every 10 mins…

Any comments? or maybe the idea is not practical or doable at all?
Thanks a lot! :slight_smile:


#2

If you don’t need realtime, you can do your lookup and calculations every 10 minutes on the server.
Then either publish the results in a special collection that’s published in realtime, or just create a method which will be called every 10 minutes by the clients.