I am running into an issue where a datebase collection refuses to go beyond 5004 documents.
I have a function that fetches a test file, daily updated, from the web and processes and creates documents per record in the file.
Function checks is a document already exists and if not creates it essentially only updating new records.
That function works for 2 minutes, reaches 5004 documents then fails with the internal curl error. Any subsequent run the function crashes in a couple for secs with the same error.
Is there some configuration that defines max records in a collection or what ??
Summary
The user is experiencing an internal curl error with a code 500. They are asking if there is a way to address the "invalid protocol" in this situation. They mention that there are no logs on the console.
Possible solutions provided by other users include:
- Breaking down the task into smaller chunks and running the function more frequently to handle the smaller chunks.
- Removing unnecessary print statements to avoid overloading the console.
- Checking if there are any other logging statements or if the code is processing a high number of records.
- Investigating if there is a limitation on the number of records in a collection in the GUI user interface.
Drake
Dec 11, 2023, 18:40
I've seen the invalid protocol error when developers try to log too much data.
Are you paginating using offset pagination? What's your code?
punti_z
Rank 3: Container
Dec 11, 2023, 18:49
Log meaning "context.log()" ? .. Not paginating. The function is dead simple, its literally
Fetch file from github,
Loop through records,
Fetch document with id from DB,
If request returns 404,
create the document
I will share the code if that will help
punti_z
Rank 3: Container
Dec 11, 2023, 18:50
But more bizzare is 5004 record wall I seem to have hit.
punti_z
Rank 3: Container
Dec 11, 2023, 19:00
A simple recreation would be to create a for loop from 1 to 10000 and create documents will Id being the number. Gonna try and report
punti_z
Rank 3: Container
Dec 11, 2023, 22:11
@Drake it is impossible to validate if it works. The GUI apparently has a limitation where after 5000 documents in a collection it just says 5000+ with no way, that I could work out, to know the actual document count in a collection. Is that so ? No where is the actual count mentioned ?
Also mean that my initial assumption of ~5000 documents total might be faulty. Maybe everything works as intended and I just can't tell because the UI is limiting visibility. The function does fail still with the same error but it runs for a couple of minutes so maybe it does everything before 500.. Can't be certain ..
Drake
Dec 11, 2023, 22:22
yes, please share the code
Drake
Dec 11, 2023, 22:23
yes, the total part of list documents caps out at 5000. We don't count further because it gets slower as the number gets higher
punti_z
Rank 3: Container
Dec 13, 2023, 02:34
''' try {
final response = await http.get(Uri.parse(url));
context.log(response.statusCode);
if (response.statusCode == 200) {
String content = utf8.decode(response.bodyBytes);
List<String> records = LineSplitter.split(content).toList();
for (String record in records) {
try {
await database.createDocument(
databaseId: envVars['APPWRITE_DATABASE_ID']!,
collectionId: 'CollectionID',
documentId: record,
data: {'data': record});
} catch (e) {
context.log("${e.toString}");
}
}
} else {
context.log('Failed to fetch $url. Status code: ${response.statusCode}');
}
I removed all context.log statements to validate but function works for 2 mins and fails with 500 ... currently about 30000 and after this the function just "return context.res.json({'ok': true});"
Drake
Dec 13, 2023, 03:04
There aren't any print statements, right?
Also, that's a very high number of records to process serially in one function execution 👀
punti_z
Rank 3: Container
Dec 13, 2023, 03:10
how would you suggest I go about processing them. Currently to accommodate for the constant 500's, I have added a random statement which randomly picks up a record and check / adds it to DB. So its at least is incrementally adding records.. No other print statements.
Drake
Dec 13, 2023, 03:13
Don't await every create document. Do 100-200 concurrently.
Break down the task into smaller chunks and have the function run more frequently to handle the smaller chunks
Drake
Dec 13, 2023, 03:15
Smaller takes that can be retired are typically better than 1 big task
punti_z
Rank 3: Container
Dec 13, 2023, 03:17
understood. but from your reading can the "invalid protocol" in such situations be addressed ? the most annoying bit about internal curl error is no logs on the console : /