Should core provide some Ajax utilities?

oc-internals

#1

Hi everyone,

I was wondering if core should provide some utility functions specially regarding ajax requests. In general, there is no control on how ajax requests are submitted, leading to some issues such as https://github.com/owncloud/core/pull/25080 and https://github.com/owncloud/core/pull/25903 .

There is one in files_externals (https://github.com/owncloud/core/blob/master/apps/files_external/js/rollingqueue.js) to run a list of requests limiting the maximum number of requests that are run at the same time, which might be useful to run a big number of requests in a more rational manner. It might need some improvements to handle a large amount of requests, but it's the starting point. We should take into consideration to make something similar (probably an improved version) available for core.

There could be another utility to handle the requests in a kind of priority queue manner. When a request comes in, if it belongs to the queue being run it will be launched immediately, but if not it will be queued to be run later. This could be used as read / write locks or could provide serialization of Ajax requests.

I think those are a couple of nice utilities that can be reused in core and in any other app, and can provide an advanced management of requests and also provide a simple interface to use those utilities.

@PVince81 @DeepDiver1975


#2

The first question would be how often do we need such utilities.
If we think that lots of apps could benefit from them, then there are two solutions:

1) Find a library that provides functions that does what we want and include it in core/vendor for anyone to use
or
2) Write that utility function ourselves. But in this case I doubt that we're the first people with this problem and maybe having a library would be better to reduce our maintenance burden.

Regarding the rolling queue, as far as I know the browser already limits the number of ajax requests and pauses subsequent ones. Maybe the rolling queue is only useful if one would like to limit the number of ajax requests below the browser's threshold without blocking other ajax requests outside of the current context (ex: image loading)