Question about program flow, beforeSave hook, afterSave hook and front end refreshing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    Question about program flow, beforeSave hook, afterSave hook and front end refreshing

    Could anybody tell me if the front end is refreshed after the beforeSave hook is executed or does it wait until both beforeSave and afterSave hooks are executed ?

    I am trying to see if I can speed up the front end by better segmenting beforeSave and afterSave instructions.

    Thanks in advance
  • tothewine
    Active Community Member
    • Jan 2018
    • 373

    #2
    afaik it is refreshed when the php api request is finished and that should include all applicable hooks. for speedup i was thinking of an extension or something that executes an "afterSaveBackground" in a cron job afterwards

    Comment

    • telecastg
      Active Community Member
      • Jun 2018
      • 907

      #3
      Thanks tothewine I greatly appreciate the information.

      I had not considered a cron job but it is a possibility, specially if there are many functions that can be executed "in the background" without interrupting the rendering process.

      In the meantime, what I have done is taking advantage of ajax asyncrhonicity and making ajax calls for "time expensive" operations that are not directly related to the entity that I am working on.

      For example, we have a "Chat" entity where users can write posts about an entity (similar to stream), and when a post is created, the system notifies a defined group of users about the new post by email.

      Originally, I had created the send email instructions as part of an afterSave hook for the Chat entity, so as confirmed by your information, the front end was needlessly waiting for the back end to execute the email send commands before re-rendering the Chat.

      Now what I have done is to create a listener for the "after:save" event in the Chat detail view setup function and when the event is triggered an ajax call is made to an entry point that sends the email notifications without interrupting the front end rendering process.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        The best way it to use Websocket. You subscribe to a specific event on frontend. Backend triggers that event and frontend is notified immediately.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment


        • tothewine
          tothewine commented
          Editing a comment
          Too bad shared hosts do not allow it often :\
      Working...