mode / alamode

A community-maintained library of visualizations for Mode reports
MIT License
70 stars 67 forks source link

Datasets not available for slow running queries, looks a lot like a race condition #67

Open kaisalmon opened 1 year ago

kaisalmon commented 1 year ago

I have a query on a mode.com report, which sometimes runs fast, and sometimes slow, depending on my {% form %} settings.

When I run a slow query, my alamode graphs are all empty. Additionally, the datasets[0].content is an empty array (and, because of this getDataFromQuery returns an empty array)

I thought I could do a clever work-around by doing something like

const addHeatMap = () => {
  let data = window.datasets[0].content // Works the same with `getDataFromQuery`
  if(data.length == 0){
    window.setTimeout(addHeatMap, 250)
    console.log("No data...")
    return
  }
  console.log(data.length)
  alamode.leafletMap(
    {
    title: "Heatmap",
    height: 700,
    lat_column: "LATITUDE",
    lng_column: "LONGITUDE",
    query_name: "Query 1",
    center_lat:  -0.02 ,
    center_lng: 51.481,
    starting_zoom: 12.5,
    dot_size: .005,
    dot_opacity: .6
    }
  )
}
addHeatMap();

But, weirdly, if the dataset had not yet loaded the first time the code was ran, then the result is always an empty array. If the first time this code runs the query has finished running, then then the dataset is available, and the graphs render correctly.

I am assuming that this is a race condition, because visually it seems to always work if the rendering of the alamode graphs occurs after the rendering of the usual mode components it always works. It is also possible that the slower query is running into some maximum dataset size which i've been unable to find documented anywhere?

Any fixes or work arounds would be appreciated

andrewsielen commented 11 months ago

I wonder if this is related to an issue I am seeing.

On queries that return a lot of rows (I can't pin down specifically the amount), alamode/datasets object just returns an empty set. If I reduce the number of results, it works.

This is what I see when I inspect the datasets object for the larger query:

Screenshot 2023-09-14 at 1 23 21 PM

It looks like it reports on the actual size, but then "oversized" is true and the content is empty.

Are there undocumented limits for alamode? It generally feels like this is not really actively supported, which is too bad because it really helps me soften out some of the edges on what Mode is capable of.

What is odd, is the exact same query in another dashboard does load in alamode. So I wonder if it isn't a dataset limit but rather a total data limit across all queries?

kaisalmon commented 10 months ago

Ah, yes, I had not noticed that oversized property. I guess this is an intentional filter then... Does seem to make heatmaps a bit pointless then, because that cut off seems to be a number small enough that you'd probably be better off with pins

Yep, it's documented here: https://mode.com/help/articles/report-layout-and-presentation#access-query-results-with-javascript

I guess then it just can't work?