Back

[SOLVED] Appwrite function issue with Future.wait for a lot of entries

  • 0
  • Databases
  • Functions
PromILLEpapst
10 Aug, 2023, 06:03

Hi, I am not sure if this is an appwrite function issue but I am supposing so. I have something I wanna loop for every entry in a list returning type Future<> building a new List<MyClass>. It works for some certain length of the list (4-5 at max). The rest fails in "An internal curl error has occurred within the executor! Error Msg: Operation timed out" ❌

TypeScript
List<CalendarWeek> newCalendarWeeks =
        await Future.wait(calendarWeeks.map((e) => getFilledCalendarWeek(
              e,
              databases,
              databaseId,
              userId,
            )));

Thought it is something with the map but same for: ❌

TypeScript
List<Future<CalendarWeek>> test = [];
    for (CalendarWeek calendarWeek in calendarWeeks) {
      test.add(getFilledCalendarWeek(
        calendarWeek,
        databases,
        databaseId,
        userId,
      ));
    }

    List<CalendarWeek> newCalendarWeeks =  await Future.wait(test);

This is a workaround that was fine for my test runs: ✅

TypeScript
List<CalendarWeek> newCalendarWeeks = [];
    
    for (int i = 0; i < calendarWeeks.length; i += 4) {
      int? endIndex = (i + 4) < calendarWeeks.length ? (i + 4) : null;
      List<CalendarWeek> subList = calendarWeeks.sublist(i, endIndex);
      newCalendarWeeks.addAll(await Future.wait(
          subList.map((calendarWeek) => getFilledCalendarWeek(
                calendarWeek,
                databases,
                databaseId,
                userId,
              ))));
    }

So it basically is about the length of entries I add in the "Future.wait([])".

Is this a common behaviour and I am missing something?

Thank you guys!

TL;DR
Issue: The user is experiencing an "Operation timed out" error when using the `Future.wait` function with a large list of entries. They suspect it may be an issue with the Appwrite function. Solution: Chunking the list and performing `Future.wait` on smaller subsets of the list resolves the issue for the user. They provided an example workaround code snippet that splits the list into smaller sublists and performs `Future.wait` on each sublist. This workaround has been successful in their test runs.
PromILLEpapst
10 Aug, 2023, 06:05

Btw:

TypeScript
getFilledCalendarWeek(...)));

Makes multiple reads on multiple database collections.

Also it is a self-hosted server. Not cloud.

Drake
10 Aug, 2023, 06:38

Right, the server might not be able to handle all the requests. Chunking it is a good approach

PromILLEpapst
10 Aug, 2023, 07:12

[SOLVED] Appwrite function issue with Future.wait for a lot of entries

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more