Skip to content

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

@kaisalmon

Description

@kaisalmon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions