(chart, projectId, user, noSource)
| 979 | } |
| 980 | |
| 981 | getPreviewData(chart, projectId, user, noSource) { |
| 982 | return this.chartCache.findLast(user.id, chart.id) |
| 983 | .then((cache) => { |
| 984 | if (noSource === "true") { |
| 985 | return new Promise((resolve) => resolve(cache)); |
| 986 | } |
| 987 | |
| 988 | return this.connectionController.findById(chart.connection_id); |
| 989 | }) |
| 990 | .then((connection) => { |
| 991 | if (noSource === "true") { |
| 992 | return new Promise((resolve) => resolve(connection)); |
| 993 | } |
| 994 | |
| 995 | const source = findSourceForConnection(connection); |
| 996 | if (source?.backend?.runChartQuery) { |
| 997 | assertSourceServerEnabled(source); |
| 998 | return source.backend.runChartQuery({ connection, query: chart.query }); |
| 999 | } |
| 1000 | |
| 1001 | return new Promise((resolve, reject) => reject("The connection type is not supported")); |
| 1002 | }) |
| 1003 | .then((data) => { |
| 1004 | const previewData = data; |
| 1005 | if (noSource !== "true" && user) { |
| 1006 | // cache, but do it async |
| 1007 | this.chartCache.create(user.id, chart.id, data); |
| 1008 | } else if (noSource) { |
| 1009 | return new Promise((resolve) => resolve(previewData.data)); |
| 1010 | } |
| 1011 | |
| 1012 | return new Promise((resolve) => resolve(data)); |
| 1013 | }) |
| 1014 | .catch((error) => { |
| 1015 | return new Promise((resolve, reject) => reject(error)); |
| 1016 | }); |
| 1017 | } |
| 1018 | |
| 1019 | previewChart(chart, projectId, user, noSource) { |
| 1020 | return this.getPreviewData(chart, projectId, user, noSource) |
no test coverage detected