coffeescript - Meteor - data fetched multiple times? -


i'm using meteor admin project stub (https://github.com/yogiben/meteor-admin).

i amended data - posts collection in main.coffee include custom filtering defined in buildpostsearch function:

router.map ->      //cut       @route "dashboard",         path: "/dashboard"         waiton: ->           [             subs.subscribe 'posts'           ]         data: ->             posts: posts.find( buildpostsearch() ).fetch()  buildpostsearch = () ->     console.log "executed."     { //filter object constructed depending on session parameters } 

this works correctly, being invoked multiple times on page refresh. can see in browser console:

executed. executed. executed. executed. executed. executed. (...around 50 times) 

i worried performance. query db many times? there better way it?

the data hook reactive, it's normal fire multiple times.

it's important remember when runs it's fetching documents your local minimongo cache , not actual database. each of find operations taking minuscule amount of time, performance not concern.

as why it's running many times, suspect may have nature of buildpostsearch. note in comments, buildpostsearch depends on session variables each time 1 of them changes, data hook execute again.

additional note: think mean data: -> , not data -> in sample code.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -