Get Free Trial

Bulk Custom Datasource API calls

Patrick Berens asked on January 22, 2021

Hi ya,
We are evaluating the Custom Datasource API and liking it so far. However, we are running into an issue for one of our use cases: Dashboards.
We would like a Dashboard to support potentially 100 widgets, each one React Flexmonster. We’ve coded this up easy enough. However, using the Flexmonster Custom Datasource API, this becomes 100 calls at a time which is a ton. We’d love to make calls in bulk and then distributed the aggregated data to each Flexmonster widget. For instance, the ‘fields’ call can obvously be done once. And we’d even like our update data calls to happen in bulk if possible.
Do you have any patterns to help with this? Maybe another customer has run into the same thing?

3 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster January 22, 2021

Hello, Patrick,
Thank you for contacting us.
We want to confirm that every single Flexmonster instance must be connected to the endpoint separately.
Currently, there are no plans to implement a single connection for several Flexmonster instances.
However, we suggest checking out the following workaround we have found for your case.
The main idea is to redirect all requests made by Flexmonster and establish the client-side proxy between the component and Flexmonster Data Server.
This would allow to cache common requests to omit multiple hitting to the server.
We have prepared the JSFiddle to demonstrate this approach:
It shows how to send an actual request only for the first instance of the component. The corresponding response will be saved and shared between other instances with the same request.
If the response is not received yet, but the request was already sent, other instances will wait for the corresponding event instead of hitting the server.
Below you can see the code snippet from the example with explanations:

let cache = {}; //this object serves as cache. It contains pairs "request" - "response"


function pivotEndpoint(requestStringified, done) {

  let request = JSON.parse(requestStringified);

  if (cache[requestStringified]) { //if requets with the same body is found, return it from the cache
  } else if (cache[requestStringified] === null) { //if request was sent, wait until it is completed and return from the cache
    document.addEventListener(requestStringified, () => {
    }, false);
  } else if (cache[requestStringified] === undefined) { //if request was not sent, write it to the "cache" object and mark with "null" value
    cache[requestStringified] = null;
    $.ajax({ //send the request to the server
      type: "POST",
      url: endpointUrl + request.type,
      data: requestStringified,
      success: response => { //after the response is received, write it to the cache and notify followers
        cache[requestStringified] = response;
        document.dispatchEvent(new Event(requestStringified));
      dataType: "json",
      contentType: "application/json"

Please note that this sample is developed only for the demonstration. This implementation may need to be changed or complemented in order to fit your needs.
For example, this example does not imply the possibility of the dataset update (you may need to clear the cache once a while).
Concerning the bulk update, we suggest saving all the references to Flexmonster instances and executing the desired API call in a loop.
Please let us know if it helps.
Our team is looking forward to hearing from you.
Kind regards,

Illia Yatsyshyn Illia Yatsyshyn Flexmonster February 1, 2021

Hello, Patrick,
Our team is wondering whether our recent suggestion was helpful for your case.
Feel free to contact us in case any further questions arise.
We are looking forward to hearing from you.
Kind regards,

Illia Yatsyshyn Illia Yatsyshyn Flexmonster February 8, 2021

Hello, Patrick,
We are reaching out to ask if you had some time to implement the suggested solution.
Please let us know if it works for your case.
Best regards,

Please login or Register to Submit Answer