From 470290b62f7b57526dc21612179fa72c6fa4b233 Mon Sep 17 00:00:00 2001 From: Johan Ahlen Date: Fri, 15 May 2020 15:37:21 +0200 Subject: [PATCH] HUE-9291 [editor] Add a default limit of 1000 records for streaming data in the result grid --- .../components/resultGrid/ko.resultGrid.js | 5 ++++- .../js/jquery/plugins/jquery.huedatatable.js | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/notebook2/components/resultGrid/ko.resultGrid.js b/desktop/core/src/desktop/js/apps/notebook2/components/resultGrid/ko.resultGrid.js index 883d335f476..039eeea117a 100644 --- a/desktop/core/src/desktop/js/apps/notebook2/components/resultGrid/ko.resultGrid.js +++ b/desktop/core/src/desktop/js/apps/notebook2/components/resultGrid/ko.resultGrid.js @@ -180,6 +180,8 @@ const TEMPLATE = ` `; +const STREAMING_MAX_ROWS = 1000; + class ResultGrid extends DisposableComponent { constructor(params, element) { super(); @@ -581,7 +583,8 @@ class ResultGrid extends DisposableComponent { dataTable.fnAddData( initial && this.data().length ? this.data() : this.lastFetchedRows(), undefined, - this.streaming + this.streaming, + STREAMING_MAX_ROWS ); } catch (e) {} const $dataTablesWrapper = $snippet.find('.dataTables_wrapper'); diff --git a/desktop/core/src/desktop/js/jquery/plugins/jquery.huedatatable.js b/desktop/core/src/desktop/js/jquery/plugins/jquery.huedatatable.js index 0c50bf3962b..794f83aa5e1 100644 --- a/desktop/core/src/desktop/js/jquery/plugins/jquery.huedatatable.js +++ b/desktop/core/src/desktop/js/jquery/plugins/jquery.huedatatable.js @@ -640,15 +640,18 @@ $.fn.hueDataTable = function(oInit) { } }; - self.fnAddData = function(mData, bRedraw, reverse) { + self.fnAddData = function(mData, bRedraw, streaming, streamRecordLimit) { const $t = self.$table; if ($t) { const aoColumns = $t.data('aoColumns') || []; - $t.data( - 'data', - reverse ? mData.reverse().concat($t.data('data')) : $t.data('data').concat(mData) - ); + const newData = streaming + ? mData.reverse().concat($t.data('data')) + : $t.data('data').concat(mData); + if (streaming && streamRecordLimit) { + newData.splice(streamRecordLimit); + } + $t.data('data', newData); if (mData.length === 0) { return;