FirebaseExtended / polymerfire

Polymer Web Components for Firebase
https://www.webcomponents.org/element/firebase/polymerfire
MIT License
459 stars 142 forks source link

performance question #267

Closed MrPhishfood closed 7 years ago

MrPhishfood commented 7 years ago

First Example

So in my app I have a list of products (at most 150) in firebase, and each item in the list includes all the subproperties that describes that item, like so:

products-list: {
  push-id: {
    name: "product name",
    price: 600,
    other: "other stuff"
    }
}

So I have a firebase-query for product-list and I iterate through the list:

<firebase-query path="/product-list" data="{{products}}"></firebase-query>

<template is="dom-repeat" items="[[products]]">
  <product-element key="item.$key"></product-element>
</template>

But what I do is only pass on the key, and in product-element I use a firebase-document to get data for that product, like so:

<firebase-document path="product-list/[[key]]" data="productData"></firebase-document>

// Do some stuff

So is there a particularly big performance penalty for me doing things this way or does polymerfire intelligently workout that I'm referencing data I already have and doesn't fetch any new data?

Second Example

In my app I have a couple of pages

<my-app-element>
  <iron-pages>
    <page1-element></page1-element>
    <page2-element></page2-element>
    <page3-element></page3-element>
    <page4-element></page4-element>
  </iron-pages>
</my-app-element>

In pages 1, 2 and 3 I need some data that I can get from:

<firebase-document path="shop-data/public" data="shopData"></firebase-document>

...and I create that element inside of those pages. Is there any performance hit to this or it is best to just create the firebase element in my-app-element and pass it down to the pages?

tjmonsi commented 7 years ago

As far as I remember, there's no impact because once you have downloaded the data using firebase, it stays in the browser. That means even if you put the same reference in another element, it just gets the data from the browser's memory and not get it from firebase.

tjmonsi commented 7 years ago

You can actually check in the websockets that it just fetch the data that is needed to populate the path tree that you want to query. Even if you have several lists, as long as those lists reference the same path, it will only load once

MrPhishfood commented 7 years ago

Thanks for the quick reply, I'm still a newbie at this stuff, I'll check out how to do the websockets thing.