Scheduled API List Race Condition?

Really could do with some help, been stuck for 2 days on this!

I have a Google Drive type clone. When a user uploads a file (“Files” dataType) via a multi file uploader I need to schedule a backend API (Scheduled API to list). In this backend it creates a file (“Files”), then depending on whether it was a Photo, Document, Video (field: “File Type”) etc it’ll Make a change to the current user’s Photo/Document/Video count. So I have 3 make a change to user’s with Only when File Type is Photo/Document/Video etc.

When I action it, every single file is created perfectly, but it never updates the current user’s count. It’s like it’s missing Step 1 in the API every single time. It’s driving me nuts. Sometimes if I upload 20 files it would show as 17 files on the count (the Files dataType shows 20 as Step 1 always works).

Any help please?

My goal is “When a user uploads multiple files I want the system to upload them to my Files datatype and update the current user’s counts on their dashboard home page.”

[grid]



when you schedule the api on a list you’ll need to add a delay between each list item - otherwise all items will try to process at one time and the count will be incorrect

alternatively you could use a scheduled api workflow to delay the count by a few seconds (until the files are created)

you could also update the count on the front end when you schedule the api workflow on a list

so 3 options:

  1. add a delay between each api list item and keep your count there
  2. add a separate count api workflow
  3. count on the front end (just reference the list your send, filter it and then add the count to the existing count)

there are pros/cons for each option so you’ll need to figure out what works for your use case

1 Like

Thank you @mitchbaylis for your reply.

  1. I’ve added a 1.5 second delay which fixed the race conditions for now but with high usage that isn’t a 100% accurate solution
  2. A second API would mean extra WU so I want to avoid that and again I’d have to have things in place in case it fails to execute.
  3. I’m using the file&multi uploader plugin, they don’t allow to access meta data to filter. The best I can do is access the file name, truncate or split the end to get the file type, and then add the count only when file type is png or jpg etc for images. The :filtered or even :split by :group by etc aren’t efficient and will significantly slow with a Google Drive clone idea of 100,000+ files. It’s only a decent solution for much less.

The only solution on bubble seems to be a recursive workflow OR a scheduled workflow with a 1.5 delay and a system in place to check that files uploaded = file count which again is an extra search and potentially an extra change “Change count -1” if it wasn’t successful.

Every solution is crap. Seems to be a major problem on Bubble.

You could instead try using the bulk create API for creating the data that files are saved to, upon the success you get the unique IDs of things created from bulk create. Use those IDs to create your list of things and apply the filers and count operator to get accurate counts.

Bulk create with API fixes race conditions in my experience.

2 Likes

Thanks @boston85719 I didn’t think of that, I’ll give it a go now :slight_smile: