Issue when the SQL query is slower than multiple requests

Posted 1 year ago by luddinus

Hi.

I have a page where an user can upload some photos.

Imagine that the limit is ten photos per user. I use dropzone to upload multiple photos, and it runs one request per photo upload.

The problem is that when I check the number of the photos inthe request, when the next request "starts", sometimes the query has not finished, so the user "sometimes" can upload more than ten photos. (I know I could do some front-end validation, but does not solve my problem.

// PhotoController
public function store()
{
   // check...
   if (request()->user()->countPhotos() >= 10)
   {
      return response()->json([
         'message' => 'You cannot upload more than 10 photos'
      ], 403);
   }

   // upload the photo...
}

What can I do to solve this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.