afterFindOne lifeCycle hook causes infinite loop

System Information
  • **Strapi Version4.0.5:
  • **Operating SystemWindows:
  • **DatabaseLiteSQL:
  • **Node Version16:

Hi everyone, I am trying to implement a viewCounter/readCounter for posts and I want to do it in a lifeCycle hook. But unfortunately even if I use strapi.db or strapi.entityService. Either way, when I try to update the field, the method I use trigger also the same hook (afterFindOne) and I end up with infinite loop.

    const entity = await strapi.db.entityManager.update("api::post.post", {
      where: { id: event.result.id },
      data: {
        readCount: 250,
      },
    });

Any help appreciated, I saw a post but it is for Strapi 3 and not works anymore.

1 Like