Announcement

Collapse
No announcement yet.

Avoid making same fetches multiple times in same page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Avoid making same fetches multiple times in same page

    Hi there,

    I'm currently trying to find ways to optimize the loading time of the most visited page of my CRM.
    This page is taking some time to load completely.

    After taking a look into the "Network" part of my chromium's web tools I noticed that a request is made MULTIPLE times for no particular reason.
    It appears that some of the custom views (for fields) used in the children (hasMany) of my page are doing a
    Code:
    getModelFactory.create
    with a
    Code:
    model.fetch()
    of the entity the user is in.

    It's not a problem to fetch the data like this but in the end this GET request is done at least 20 times (and it can be worse).

    To add some precisions :
    - The GET request is already did one time at the setup of the page. (It's the detail page of one of my custom entity).

    Is there a solution for this king of problem ?

    Firyo.

  • #2
    Hi Firyo,

    It's likely you need to revise your code so that it does not fetch. It's impossible to answer on your question as information you provided is not detail enough to understand.

    Comment


    • #3
      Thanks for your answer yuri.

      Here is some detail (I'll hope this will help you and the other understanding what I'm talking about).

      First here is a schema explaining my relation.

      Click image for larger version  Name:	schema_espocrm.png Views:	0 Size:	12.1 KB ID:	94231

      My detail page (which I'm trying to optimize) of "Parent entity" displays all the "child entity" that are linked to it.

      In these "child entity" I have multiple fields that have a custom JS view.
      In these JS views there is a similar code like this.

      Code:
      Espo.define('myExtension:views/childEntity/fields/field', 'views/fields/link', function (Dep) {
      return Dep.extend({
      
      filtersData: [],
      
      setup: function () {
      Dep.prototype.setup.call(this);
      
      var that = this;
      var parentEntityId = this.model.get('parentEntityId');
      
      if(parentEntityId !== undefined && parentEntityId !== '') {
      
      that.wait(true);
      this.getModelFactory().create('ParentEntity', function (model) {
      model.id = parentEntityId;
      model.fetch().then(function () {
      
      that.filtersData['id'] = {
      type: 'in',
      value: model.get('fieldIds'),
      data: {
      type: 'anyOf',
      nameValue: model.get('fieldNames')
      }
      };
      
      that.wait(false);
      }.bind(this));
      });
      }
      
      },
      
      getSelectFilters: function () {
      Dep.prototype.getSelectFilters.call(this);
      return this.filtersData;
      }
      
      });
      });​
      Click image for larger version

Name:	image_2023-06-21_120644646.png
Views:	150
Size:	84.1 KB
ID:	94232

      Comment


      • #4
        You can create a new API endpoint that will fetch all records at once, and then pass specific record data to child views.

        Comment


        • #5
          Originally posted by yuri View Post
          You can create a new API endpoint that will fetch all records at once, and then pass specific record data to child views.
          Hmm, I'll check that. thanks anyway.

          Comment

          Working...
          X