#Server still timing out on 1.8.2 on prefetch={true}

17 messages · Page 1 of 1 (latest)

smoky narwhal
#

Despite the fix by Adrien, the server still seems to time out due to too many database connections opened on 1.8.2. This happens e.g. on the standard /store route. As soon as I removed the prefetch={false} from my <Link/> components the server started to timeout and become unresponsive immediately.

Is there any way this can be looked into again? Its seriously degrading our SEO and UX in general and slowing down our development massively.

midnight willow
#

do you have a thread with context on this issue?

smoky narwhal
smoky narwhal
#

I am calling my custom route that in turn makes a db call over the extended product category service: Is there a specific way I need to close the db connection to prevent the timouts? This is really pressing atm, we cant really deploy and I am considering to revert back to 1.7.8 once again where things worked just fine...

midnight willow
#

Let me take a look at this. Is it just your custom route or products route and product categories routes as well?

smoky narwhal
#

It’s happening everywhere on /store but also on my custom routes as soon as I enable prefetch on Link components in Nextjs.

midnight willow
#

We're investigating this @smoky narwhal .

#

In the meantime, can you do a limit=10&expand=variants on all product list endpoints and see if that works?

glad vapor
#

Just to confirm, this was actually working fine for me, but all of a sudden has started doing the same - my api has begun timing out again, in my instance whilst loading a product page, querying a single, i also query the products route with a filter that returns ~10 products marked with a specific tag - at this point my api times out and have to restart the service, works fine in development mode, but fails on production

midnight willow
#

Thanks for the feedback @glad vapor. We've been investigating this. We've identified a fix for the product retrieve endpoint, with an open PR. I'll move my efforts to the list endpoint now.

glad vapor
#

👌

smoky narwhal
#

Thanks that sounds great!

#

Riqwan - thanks for your efforts, its highly appreciated 🙏.

I actually extended the product-category service like this to retrieve category ancestors:

class ProductCategoryService extends MedusaProductCategoryService {
  /**
   * Retrieves a product category by id.
   * @param productCategoryId - the id of the product category to retrieve.
   * @param config - the config of the product category to retrieve.
   * @return the product category.
   */
  async retrieveByHandle(
    handle: string,
    config: FindConfig<ProductCategory> = {},
    selector: Selector<ProductCategory> = {}
  ): Promise<ProductCategory> {
    if (!isDefined(handle)) {
      throw new MedusaError(
        MedusaError.Types.NOT_FOUND,
        `"handle" must be defined`
      );
    }

    const selectors = Object.assign({ handle: handle }, selector);
    const query = buildQuery(selectors, config);
    const productCategoryRepo = this.activeManager_.withRepository(
      this.productCategoryRepo_
    );

    const productCategoryWithDescendants = await productCategoryRepo.findOne(
      query
    );

    const productCategoryWithParents =
      await productCategoryRepo.findAncestorsTree(
        productCategoryWithDescendants
      );

    if (!productCategoryWithDescendants) {
      throw new MedusaError(
        MedusaError.Types.NOT_FOUND,
        `Handle: ${handle} was not found`
      );
    }

    return productCategoryWithParents;
  }

This is the first route I built

#
  /**
   * Fetches unique product category handles.
   * @return an array of unique and non null product category handles.
   */
  async retrieveUniqueHandles(): Promise<string[]> {
    const productCategoryRepo = this.activeManager_.withRepository(
      this.productCategoryRepo_
    );

    const uniqueHandles = await productCategoryRepo
      .createQueryBuilder("ProductCategory")
      .select("DISTINCT(ProductCategory.handle)", "handle")
      .where("handle IS NOT NULL")
      .getRawMany()
      .then((rows) => rows.map((row) => row.handle));

    if (!uniqueHandles) {
      throw new MedusaError(MedusaError.Types.NOT_FOUND, `No handles found`);
    }

    return uniqueHandles;
  }

And I built this second one to fetch all category handles in order to fetch them all in getStaticPaths .

Am I maybe doing something really wrong here that causes these timeouts?

smoky narwhal
#

Is this fixed with version 1.9.0? Or is this unrelated? Thanks so much 🙏

midnight willow
#

@smoky narwhal we're in the final stages of a merge. We had to fix a bug in typeorm - https://github.com/typeorm/typeorm/pull/9990

Its taking them a bit of time to review it, so we're probably going to fork it in the meantime

GitHub

fix issue - createQueryBuilder in repository loses queryplanner when wrapped in txn upsteam until RelationIdLoader
Closes: #9988
Description of change
When we create relationships within a transact...