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

/rest/batch/people very slow response when payload incorrect #5523

Closed
waynehamadi opened this issue May 21, 2024 · 4 comments
Closed

/rest/batch/people very slow response when payload incorrect #5523

waynehamadi opened this issue May 21, 2024 · 4 comments
Assignees
Labels
T type: bug Something isn't working

Comments

@waynehamadi
Copy link

waynehamadi commented May 21, 2024

Bug Description

Example:

export async function main(twenty_api_key: string, data: Array) {
  const url = 'https://api.twenty.com/rest/batch/people';
  const options = {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Authorization': `Bearer ${twenty_api_key}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(data[0])
  };
  const response = await fetch(url, options);
  return await response.text()
}


data =
[
  {
    "email": "koz@bionluk.com",
    "jobTitle": "Angel Investor",
    "lastName": "Koz",
    "firstName": "Muenif",
    "linkedinLink": {
      "url": "http://www.linkedin.com/in/munifkoz",
      "label": "LinkedIn"
    }
  }
]

As you can see, firstname and lastname are put incorrectly.

I get a 520 but it takes minutes to get back an answer. Which is pretty slow

Expected behavior

Quicker response

@waynehamadi waynehamadi added the type: bug Something isn't working label May 21, 2024
Copy link

greptile-apps bot commented May 21, 2024

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).

To address the slow response when the payload is incorrect, consider adding validation and error handling in the fetchBatch method within fetch-by-batch.service.ts. Specifically, validate the payload before making the HTTP request and return an error immediately if the payload is invalid. Here is a possible implementation:

// In fetch-by-batch.service.ts

private validatePayload(payload: any): boolean {
  // Add your validation logic here
  return payload && payload.firstName && payload.lastName;
}

async fetchBatch(queries: any[], accessToken: string, batchOffset: number, batchLimit: number, boundary: string): Promise<AxiosResponse> {
  if (!this.validatePayload(queries[0])) {
    throw new Error('Invalid payload');
  }
  // Existing implementation
}

This will ensure that invalid payloads are caught early, reducing the time taken to respond with an error.

References

/packages/twenty-server/src/modules/messaging/services/fetch-by-batch.service.ts
/packages/twenty-server/src/modules/messaging/services/fetch-by-batch.service.ts

Ask Greptile

@waynehamadi waynehamadi changed the title Very slow response when payload incorrect /rest/batch/people very slow response when payload incorrect May 21, 2024
@FelixMalfait
Copy link
Member

@martmull would you have any idea where this could come from? It seems 200 for batch response are very fast but 500 are slow. I would have expected the opposite as 200 involves writing to the DB and doing more things

@martmull
Copy link
Contributor

can't reproduce

@martmull
Copy link
Contributor

Closing for now, please don't hesitate to reopen the issue if the pb persists, I might miss something when trying to reproduce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T type: bug Something isn't working
Projects
Status: ✅ Done
Development

No branches or pull requests

3 participants