Giter Site home page Giter Site logo

Comments (2)

dominiks avatar dominiks commented on May 26, 2024 1

Hi Zoltan, I tried modifying the adapter's behaviour with shouldBackgroundReloadAll and shouldReloadAll but that didn't help. I agree that I could probably solve the problem by adding real time communication via websockets between the ember store and the server but that is probably complete overkill if one does not need it to be realtime.

But it turns out other people are having the same issue: emberjs/data#4564
The findAll() method ignores items that are missing in the server response but still present in the local cache and it looks like this is not going to change. This is the expected and documented behaviour of findAll():

findAll asks the adapter's findAll method to find the records for the given type, and returns a promise which will resolve with all records of this type present in the store, even if the adapter only returns a subset of them.

So in the end I found 2 workarounds for this:

  1. Clear the local cache of library objects if you're going to load them all
model() {
  this.store.unloadAll("library");
  return this.store.findAll("library");
}
  1. Use query() which doesn't do this. If you want to load all objects pass an empty hash as the parameter or parameters your server will ignore:
model() {
  return this.store.query("library", {});
}

I feel that with these workarounds the issue is acceptable as one might usually use query() on large datasets instead of findAll() anyways to have pagination, filtering and such.

Thanks four your quick response and helping me find a workable solution. 👍

from library-app.

zoltan-nz avatar zoltan-nz commented on May 26, 2024

@dominiks Hey Dominiks, thank you.

Great findings and you are right. I noticed the same when I started to play with Firebase. As I see Firebase realtime sync your data when you create a new item, however they don't sync "delete", so it is not realtime... As I see here, in Firebase doc, the official Firebase library supports this option, maybe this is missing from the Emberfire package.

If you built your own server backend, you have to manually setup realtime "websocket" communication.

You can check out this hooks also in Ember Adapter:
https://www.emberjs.com/api/ember-data/3.7/classes/DS.Adapter/methods/shouldReloadAll?anchor=shouldBackgroundReloadAll

You can force your Adapter to reload all the records from the server. So it is always try to find out what is the latest state of your database. Maybe this is only what you need.

Hope this could help, don't hesitate to share your findings and let me know which solution worked. :)

from library-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.