@@ -9,7 +9,7 @@ const logger = debug("redash:services:QueryResult");
99const filterTypes = [ "filter" , "multi-filter" , "multiFilter" ] ;
1010
1111function defer ( ) {
12- const result = { onStatusChange : status => { } } ;
12+ const result = { onStatusChange : ( status ) => { } } ;
1313 result . promise = new Promise ( ( resolve , reject ) => {
1414 result . resolve = resolve ;
1515 result . reject = reject ;
@@ -40,13 +40,13 @@ function getColumnNameWithoutType(column) {
4040}
4141
4242function getColumnFriendlyName ( column ) {
43- return getColumnNameWithoutType ( column ) . replace ( / (?: ^ | \s ) \S / g, a => a . toUpperCase ( ) ) ;
43+ return getColumnNameWithoutType ( column ) . replace ( / (?: ^ | \s ) \S / g, ( a ) => a . toUpperCase ( ) ) ;
4444}
4545
46- const createOrSaveUrl = data => ( data . id ? `api/query_results/${ data . id } ` : "api/query_results" ) ;
46+ const createOrSaveUrl = ( data ) => ( data . id ? `api/query_results/${ data . id } ` : "api/query_results" ) ;
4747const QueryResultResource = {
4848 get : ( { id } ) => axios . get ( `api/query_results/${ id } ` ) ,
49- post : data => axios . post ( createOrSaveUrl ( data ) , data ) ,
49+ post : ( data ) => axios . post ( createOrSaveUrl ( data ) , data ) ,
5050} ;
5151
5252export const ExecutionStatus = {
@@ -97,11 +97,11 @@ function handleErrorResponse(queryResult, error) {
9797}
9898
9999function sleep ( ms ) {
100- return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
100+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
101101}
102102
103103export function fetchDataFromJob ( jobId , interval = 1000 ) {
104- return axios . get ( `api/jobs/${ jobId } ` ) . then ( data => {
104+ return axios . get ( `api/jobs/${ jobId } ` ) . then ( ( data ) => {
105105 const status = statuses [ data . job . status ] ;
106106 if ( status === ExecutionStatus . WAITING || status === ExecutionStatus . PROCESSING ) {
107107 return sleep ( interval ) . then ( ( ) => fetchDataFromJob ( data . job . id ) ) ;
@@ -146,7 +146,7 @@ class QueryResult {
146146 // TODO: we should stop manipulating incoming data, and switch to relaying
147147 // on the column type set by the backend. This logic is prone to errors,
148148 // and better be removed. Kept for now, for backward compatability.
149- each ( this . query_result . data . rows , row => {
149+ each ( this . query_result . data . rows , ( row ) => {
150150 forOwn ( row , ( v , k ) => {
151151 let newType = null ;
152152 if ( isNumber ( v ) ) {
@@ -173,7 +173,7 @@ class QueryResult {
173173 } ) ;
174174 } ) ;
175175
176- each ( this . query_result . data . columns , column => {
176+ each ( this . query_result . data . columns , ( column ) => {
177177 column . name = "" + column . name ;
178178 if ( columnTypes [ column . name ] ) {
179179 if ( column . type == null || column . type === "string" ) {
@@ -265,14 +265,14 @@ class QueryResult {
265265
266266 getColumnNames ( ) {
267267 if ( this . columnNames === undefined && this . query_result . data ) {
268- this . columnNames = this . query_result . data . columns . map ( v => v . name ) ;
268+ this . columnNames = this . query_result . data . columns . map ( ( v ) => v . name ) ;
269269 }
270270
271271 return this . columnNames ;
272272 }
273273
274274 getColumnFriendlyNames ( ) {
275- return this . getColumnNames ( ) . map ( col => getColumnFriendlyName ( col ) ) ;
275+ return this . getColumnNames ( ) . map ( ( col ) => getColumnFriendlyName ( col ) ) ;
276276 }
277277
278278 getTruncated ( ) {
@@ -286,7 +286,7 @@ class QueryResult {
286286
287287 const filters = [ ] ;
288288
289- this . getColumns ( ) . forEach ( col => {
289+ this . getColumns ( ) . forEach ( ( col ) => {
290290 const name = col . name ;
291291 const type = name . split ( "::" ) [ 1 ] || name . split ( "__" ) [ 1 ] ;
292292 if ( includes ( filterTypes , type ) ) {
@@ -302,8 +302,8 @@ class QueryResult {
302302 }
303303 } , this ) ;
304304
305- this . getRawData ( ) . forEach ( row => {
306- filters . forEach ( filter => {
305+ this . getRawData ( ) . forEach ( ( row ) => {
306+ filters . forEach ( ( filter ) => {
307307 filter . values . push ( row [ filter . name ] ) ;
308308 if ( filter . values . length === 1 ) {
309309 if ( filter . multiple ) {
@@ -315,8 +315,8 @@ class QueryResult {
315315 } ) ;
316316 } ) ;
317317
318- filters . forEach ( filter => {
319- filter . values = uniqBy ( filter . values , v => {
318+ filters . forEach ( ( filter ) => {
319+ filter . values = uniqBy ( filter . values , ( v ) => {
320320 if ( moment . isMoment ( v ) ) {
321321 return v . unix ( ) ;
322322 }
@@ -345,12 +345,12 @@ class QueryResult {
345345
346346 axios
347347 . get ( `api/queries/${ queryId } /results/${ id } .json` )
348- . then ( response => {
348+ . then ( ( response ) => {
349349 // Success handler
350350 queryResult . isLoadingResult = false ;
351351 queryResult . update ( response ) ;
352352 } )
353- . catch ( error => {
353+ . catch ( ( error ) => {
354354 // Error handler
355355 queryResult . isLoadingResult = false ;
356356 handleErrorResponse ( queryResult , error ) ;
@@ -362,10 +362,10 @@ class QueryResult {
362362 loadLatestCachedResult ( queryId , parameters ) {
363363 axios
364364 . post ( `api/queries/${ queryId } /results` , { queryId, parameters } )
365- . then ( response => {
365+ . then ( ( response ) => {
366366 this . update ( response ) ;
367367 } )
368- . catch ( error => {
368+ . catch ( ( error ) => {
369369 handleErrorResponse ( this , error ) ;
370370 } ) ;
371371 }
@@ -375,11 +375,11 @@ class QueryResult {
375375 this . deferred . onStatusChange ( ExecutionStatus . LOADING_RESULT ) ;
376376
377377 QueryResultResource . get ( { id : this . job . query_result_id } )
378- . then ( response => {
378+ . then ( ( response ) => {
379379 this . update ( response ) ;
380380 this . isLoadingResult = false ;
381381 } )
382- . catch ( error => {
382+ . catch ( ( error ) => {
383383 if ( tryCount === undefined ) {
384384 tryCount = 0 ;
385385 }
@@ -394,9 +394,12 @@ class QueryResult {
394394 } ) ;
395395 this . isLoadingResult = false ;
396396 } else {
397- setTimeout ( ( ) => {
398- this . loadResult ( tryCount + 1 ) ;
399- } , 1000 * Math . pow ( 2 , tryCount ) ) ;
397+ setTimeout (
398+ ( ) => {
399+ this . loadResult ( tryCount + 1 ) ;
400+ } ,
401+ 1000 * Math . pow ( 2 , tryCount )
402+ ) ;
400403 }
401404 } ) ;
402405 }
@@ -410,19 +413,26 @@ class QueryResult {
410413 : axios . get ( `api/queries/${ query } /jobs/${ this . job . id } ` ) ;
411414
412415 request
413- . then ( jobResponse => {
416+ . then ( ( jobResponse ) => {
414417 this . update ( jobResponse ) ;
415418
416419 if ( this . getStatus ( ) === "processing" && this . job . query_result_id && this . job . query_result_id !== "None" ) {
417420 loadResult ( ) ;
418421 } else if ( this . getStatus ( ) !== "failed" ) {
419- const waitTime = tryNumber > 10 ? 3000 : 500 ;
422+ let waitTime ;
423+ if ( tryNumber <= 10 ) {
424+ waitTime = 500 ;
425+ } else if ( tryNumber <= 50 ) {
426+ waitTime = 1000 ;
427+ } else {
428+ waitTime = 3000 ;
429+ }
420430 setTimeout ( ( ) => {
421431 this . refreshStatus ( query , parameters , tryNumber + 1 ) ;
422432 } , waitTime ) ;
423433 }
424434 } )
425- . catch ( error => {
435+ . catch ( ( error ) => {
426436 logger ( "Connection error" , error ) ;
427437 // TODO: use QueryResultError, or better yet: exception/reject of promise.
428438 this . update ( {
@@ -451,14 +461,14 @@ class QueryResult {
451461
452462 axios
453463 . post ( `api/queries/${ id } /results` , { id, parameters, apply_auto_limit : applyAutoLimit , max_age : maxAge } )
454- . then ( response => {
464+ . then ( ( response ) => {
455465 queryResult . update ( response ) ;
456466
457467 if ( "job" in response ) {
458468 queryResult . refreshStatus ( id , parameters ) ;
459469 }
460470 } )
461- . catch ( error => {
471+ . catch ( ( error ) => {
462472 handleErrorResponse ( queryResult , error ) ;
463473 } ) ;
464474
@@ -481,14 +491,14 @@ class QueryResult {
481491 }
482492
483493 QueryResultResource . post ( params )
484- . then ( response => {
494+ . then ( ( response ) => {
485495 queryResult . update ( response ) ;
486496
487497 if ( "job" in response ) {
488498 queryResult . refreshStatus ( query , parameters ) ;
489499 }
490500 } )
491- . catch ( error => {
501+ . catch ( ( error ) => {
492502 handleErrorResponse ( queryResult , error ) ;
493503 } ) ;
494504
0 commit comments