mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Reverting patch for RM #3269.
We observed that sometimes the browser is getting hanged and sometimes the ViewData grid is getting disappear. We suspect its due to the number of rows to update on the slick grid after fetching next of rows.
This commit is contained in:
committed by
Akshay Joshi
parent
dfb74904ed
commit
17129b259b
@@ -97,7 +97,6 @@ class SqlEditorModule(PgAdminModule):
|
||||
'sqleditor.query_tool_start',
|
||||
'sqleditor.poll',
|
||||
'sqleditor.fetch',
|
||||
'sqleditor.fetch_till',
|
||||
'sqleditor.fetch_all',
|
||||
'sqleditor.save',
|
||||
'sqleditor.inclusive_filter',
|
||||
@@ -534,24 +533,18 @@ def poll(trans_id):
|
||||
'/fetch/<int:trans_id>/<int:fetch_all>', methods=["GET"],
|
||||
endpoint='fetch_all'
|
||||
)
|
||||
@blueprint.route(
|
||||
'/fetch/<int:trans_id>/<int:fetch_till>', methods=["GET"],
|
||||
endpoint='fetch_till'
|
||||
)
|
||||
@login_required
|
||||
def fetch(trans_id, fetch_all=None, fetch_till=None):
|
||||
def fetch(trans_id, fetch_all=None):
|
||||
result = None
|
||||
has_more_rows = False
|
||||
rows_fetched_from = 0
|
||||
rows_fetched_to = 0
|
||||
fetch_row_cnt = -1 if fetch_all == 1 else ON_DEMAND_RECORD_COUNT
|
||||
|
||||
# Check the transaction and connection status
|
||||
status, error_msg, conn, trans_obj, session_obj = \
|
||||
check_transaction_status(trans_id)
|
||||
|
||||
fetch_row_cnt = -1 if fetch_all == 1 else ON_DEMAND_RECORD_COUNT \
|
||||
if fetch_till is None else fetch_till - trans_obj.get_fetched_row_cnt()
|
||||
|
||||
if error_msg == gettext('Transaction ID not found in the session.'):
|
||||
return make_json_response(success=0, errormsg=error_msg,
|
||||
info='DATAGRID_TRANSACTION_REQUIRED',
|
||||
@@ -564,6 +557,8 @@ def fetch(trans_id, fetch_all=None, fetch_till=None):
|
||||
else:
|
||||
status = 'Success'
|
||||
res_len = len(result)
|
||||
if fetch_row_cnt != -1 and res_len == ON_DEMAND_RECORD_COUNT:
|
||||
has_more_rows = True
|
||||
|
||||
if res_len:
|
||||
rows_fetched_from = trans_obj.get_fetched_row_cnt()
|
||||
@@ -572,9 +567,6 @@ def fetch(trans_id, fetch_all=None, fetch_till=None):
|
||||
rows_fetched_to = trans_obj.get_fetched_row_cnt()
|
||||
session_obj['command_obj'] = pickle.dumps(trans_obj, -1)
|
||||
update_session_grid_transaction(trans_id, session_obj)
|
||||
|
||||
if fetch_row_cnt != -1 and rows_fetched_to < conn.rows_affected():
|
||||
has_more_rows = True
|
||||
else:
|
||||
status = 'NotConnected'
|
||||
result = error_msg
|
||||
|
||||
@@ -737,12 +737,6 @@ define('tools.querytool', [
|
||||
|
||||
// This function is responsible to create and render the SlickGrid.
|
||||
render_grid: function(collection, columns, is_editable, client_primary_key, rows_affected) {
|
||||
if (rows_affected) {
|
||||
let dummyCollection = new Array(rows_affected - collection.length);
|
||||
// Adding dummy rows to adjust height, rows data will be update as and when user scrolls down in DataView panel
|
||||
dummyCollection.fill([gettext('Loading...')]);
|
||||
collection = [...collection, ...dummyCollection];
|
||||
}
|
||||
var self = this;
|
||||
|
||||
self.handler.numberOfModifiedCells = 0;
|
||||
@@ -1212,18 +1206,13 @@ define('tools.querytool', [
|
||||
$('#btn-save-data').prop('disabled', false);
|
||||
}.bind(editor_data));
|
||||
|
||||
grid.onScroll.subscribe((e, args) => {
|
||||
clearTimeout($.data(this, 'scrollTimer'));
|
||||
$.data(this, 'scrollTimer', setTimeout(function () {
|
||||
if (self.handler.has_more_rows && !self.handler.fetching_rows && args.grid.getViewport().bottom > self.handler.rows_fetched_to + self.handler.rows_fetch_batch_count) {
|
||||
// fast scrolling using slider
|
||||
let fetch_till = (parseInt(args.grid.getViewport().bottom / self.handler.rows_fetch_batch_count) + 1) * self.handler.rows_fetch_batch_count;
|
||||
self.fetch_next(null, null, fetch_till);
|
||||
}
|
||||
}, 250));
|
||||
// If its gentle scroll, when last 10% of rows are left to scroll then fetch next batch of rows
|
||||
if (self.handler.has_more_rows && !self.handler.fetching_rows && args.grid.getViewport().bottom + (self.handler.rows_fetch_batch_count * 0.1) > self.handler.rows_fetched_to) {
|
||||
// gentle scroll using mouse
|
||||
// Listen grid viewportChanged event to load next chunk of data.
|
||||
grid.onViewportChanged.subscribe(function(e, args) {
|
||||
var rendered_range = args.grid.getRenderedRange(),
|
||||
data_len = args.grid.getDataLength();
|
||||
// start fetching next batch of records before reaching to bottom.
|
||||
if (self.handler.has_more_rows && !self.handler.fetching_rows && rendered_range.bottom > data_len - 100) {
|
||||
// fetch asynchronous
|
||||
setTimeout(self.fetch_next.bind(self));
|
||||
}
|
||||
});
|
||||
@@ -1272,7 +1261,7 @@ define('tools.querytool', [
|
||||
this.fetch_next(true, cb);
|
||||
},
|
||||
|
||||
fetch_next: function(fetch_all, cb, fetch_till) {
|
||||
fetch_next: function(fetch_all, cb) {
|
||||
var self = this,
|
||||
url = '';
|
||||
|
||||
@@ -1293,18 +1282,11 @@ define('tools.querytool', [
|
||||
'fetch_all': 1,
|
||||
});
|
||||
} else {
|
||||
if (fetch_till) {
|
||||
url = url_for('sqleditor.fetch_till', {
|
||||
'trans_id': self.transId,
|
||||
fetch_till: fetch_till,
|
||||
});
|
||||
} else {
|
||||
url = url_for('sqleditor.fetch', {
|
||||
'trans_id': self.transId,
|
||||
});
|
||||
}
|
||||
url = url_for('sqleditor.fetch', {
|
||||
'trans_id': self.transId,
|
||||
});
|
||||
}
|
||||
self.handler.last_rows_fetched_to = self.handler.rows_fetched_to;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
@@ -1314,8 +1296,7 @@ define('tools.querytool', [
|
||||
$('#btn-flash').prop('disabled', false);
|
||||
$('#btn-download').prop('disabled', false);
|
||||
self.handler.trigger('pgadmin-sqleditor:loading-icon:hide');
|
||||
self.handler.rows_fetched_to = res.data.rows_fetched_to;
|
||||
setTimeout(() => self.update_grid_data(res.data.result), 100);
|
||||
self.update_grid_data(res.data.result);
|
||||
self.handler.fetching_rows = false;
|
||||
if (typeof cb == 'function') {
|
||||
cb();
|
||||
@@ -1341,15 +1322,16 @@ define('tools.querytool', [
|
||||
|
||||
update_grid_data: function(data) {
|
||||
this.dataView.beginUpdate();
|
||||
for (var i = 0, k = this.handler.last_rows_fetched_to; k < this.handler.rows_fetched_to; i++ , k++) {
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
// Convert 2darray to dict.
|
||||
var item = {};
|
||||
for (var j = 1; j < this.grid_columns.length; j++) {
|
||||
item[this.grid_columns[j]['field']] = data[i][this.grid_columns[j]['pos']];
|
||||
}
|
||||
|
||||
item['__temp_PK'] = k;
|
||||
this.dataView.updateItem(k, item);
|
||||
item[this.client_primary_key] = (this.client_primary_key_counter++).toString();
|
||||
this.dataView.addItem(item);
|
||||
}
|
||||
|
||||
this.dataView.endUpdate();
|
||||
@@ -2246,7 +2228,6 @@ define('tools.querytool', [
|
||||
self.marked_line_no = 0;
|
||||
self.has_more_rows = false;
|
||||
self.fetching_rows = false;
|
||||
self.rows_fetched_to = 0;
|
||||
self.close_on_save = false;
|
||||
self.close_on_idle_transaction = false;
|
||||
self.last_transaction_status = -1;
|
||||
@@ -2693,8 +2674,6 @@ define('tools.querytool', [
|
||||
// Make sure - the 'Data Output' panel is visible, before - we
|
||||
// start rendering the grid.
|
||||
self.gridView.data_output_panel.focus();
|
||||
self.gridView.handler.rows_fetched_to = data.rows_fetched_to;
|
||||
self.gridView.handler.rows_fetch_batch_count = data.rows_fetched_to - (data.rows_fetched_from - 1);
|
||||
setTimeout(
|
||||
function() {
|
||||
self.gridView.render_grid(data.result, self.columns,
|
||||
|
||||
Reference in New Issue
Block a user