vue-meteor-tracker icon indicating copy to clipboard operation
vue-meteor-tracker copied to clipboard

Performance: unwanted executions of transform() function

Open red-meadow opened this issue 7 years ago • 0 comments
trafficstars

Hello!

I use collections/cursors with defined transform() function to transform raw documents to class instances. Normally, this function is executed when a document is fetched for the 1st time or updated. But with vue-meteor-tracker it's re-executed for all matching documents if one of them has been changed. Please, take a look at the code:

<template>
  <main>
    <div v-for="note in notes">
      {{ note.text }}
    </div>
  </main>
</template>
<script>
import Notes from '/imports/Notes'

export default {
  meteor:  {
    $subscribe: {
      'notes.all': []
    },
    notes() {
      return Notes.find({}, {
        transform(note) {
          console.log('transformed');
          return note
        }
      })
    }
  }
}
</script>
// server.js
create7Notes()

// later
updateSingleNote()  //  => 7 'transformed' messages in the browser

As you see, each note is transformed again even if it wasn't updated. That might be a problem for the large datasets. I tried the same scenario in Blaze using {{#each .. in}} helper and everything works as expected: transfom() is re-executed only for the updated document.

Is this an expected behavior for vue-meteor? Is there a way to change it?

Thank you in advance!

red-meadow avatar Jun 08 '18 18:06 red-meadow