Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabrica slowness and timeouts on certain pages due to model relationships that cause unnecessary API calls #766

Open
svogt0511 opened this issue Aug 23, 2023 · 0 comments

Comments

@svogt0511
Copy link
Contributor

svogt0511 commented Aug 23, 2023

This is a general issue with the way Ember-Data works, but it has especially been showing up on the pages that display individual contacts.

Display of an individual contact in Fabrica (/contacts/:id) can result in many individual API requests to load all of the related provider contacts. For example https://doi.stage.datacite.org/contacts/ca485a42-c5b1-4f5c-8464-c6d8a753f27c (see the screenshot) loads numerous contacts even though only one is needed.

This causes slowness and timeouts in some Fabrica pages, and an unnecessary load on the REST API.

This has to do with the belongsTo/hasMany model relationship , especially when the 'async' is set to true for the relationship:

/ app/models/contact.js 
export default Model.extend(Validations, {
  provider: belongsTo('provider', {
    async: false
  }),
. . .
}

This happens when findRecord is called in the model hook for records with such relationships, especially if there are a lot of related records.

// app/routes/contacts/show.js
 model(params) {
    let self = this;
    return this.store
      .findRecord('contact', params.contact_id, { include: 'provider' })
      .then(function (contact) {
        self.headData.set('title', contact.name);

        return contact;
      })
      .catch(function (reason) {
        console.debug(reason);

        self.get('flashMessages').warning(reason);
        self.transitionTo('index');
      });
  },

Other developers have reported this as an issue with Ember and have been promised future improvements. A workaround is to have an adapter that can 'coalesce' these separate API calls into 1 API call, but the API has to be designed for it. There may be a way to restructure the code to avoid this situation.

This has caused timeouts in our test suites due to the build up of unused contacts over time. The workaround there has been to have tests clean up unused contacts at the end of the run.

Finally, this happens with other model relationships in Fabrica, for instance many repository records can be loaded on the page which displays a single repository.

image
@svogt0511 svogt0511 changed the title Fabrica page slowness and timeouts on certain pages due to model relationships that cause unnecessary API calls Fabrica slowness and timeouts on certain pages due to model relationships that cause unnecessary API calls Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant