From 5e91ed2bb1123b7bc7a96ee783d50b8b8b2f716b Mon Sep 17 00:00:00 2001 From: Nagesh Dhope Date: Wed, 22 Apr 2020 17:54:32 +0530 Subject: [PATCH] Fixed slider jump issue by making an API call to fetch the next batch of rows only after a user stops scrolling down. Fixes #3269 --- web/pgadmin/tools/sqleditor/__init__.py | 5 +++-- .../tools/sqleditor/static/js/sqleditor.js | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 35e1bf3dc..88bc3c959 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -564,8 +564,6 @@ 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() @@ -574,6 +572,9 @@ 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 diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index d41244ce6..e0a6c99b4 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -1213,12 +1213,17 @@ define('tools.querytool', [ }.bind(editor_data)); grid.onScroll.subscribe((e, args) => { - 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 - let fetch_till = ((args.grid.getViewport().bottom % self.handler.rows_fetch_batch_count) + 1) * self.handler.rows_fetch_batch_count; - self.fetch_next(null, null, fetch_till); - } else if (self.handler.has_more_rows && !self.handler.fetching_rows && args.grid.getViewport().bottom + 100 > self.handler.rows_fetched_to) { - // gentle scroll + 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 setTimeout(self.fetch_next.bind(self)); } }); @@ -1310,7 +1315,7 @@ define('tools.querytool', [ $('#btn-download').prop('disabled', false); self.handler.trigger('pgadmin-sqleditor:loading-icon:hide'); self.handler.rows_fetched_to = res.data.rows_fetched_to; - self.update_grid_data(res.data.result); + setTimeout(() => self.update_grid_data(res.data.result), 100); self.handler.fetching_rows = false; if (typeof cb == 'function') { cb();