Skip to content

Commit 5bd6bce

Browse files
committed
Fix review comments.
1 parent 78987d5 commit 5bd6bce

File tree

13 files changed

+39
-46
lines changed

13 files changed

+39
-46
lines changed
-208 KB
Binary file not shown.

docs/en_US/preferences.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,10 @@ Use the fields on the *Options* panel to manage editor preferences.
535535
will warn upon clicking the *Execute Query* button in the query tool. The warning
536536
will appear only if *Underline query at cursor?* is set to *False*.
537537

538+
* When the *Use server cursor?* switch is set to *True*, the dataset will be fetched
539+
using a server-side cursor after the query is executed.
540+
541+
538542
.. image:: images/preferences_sql_results_grid.png
539543
:alt: Preferences dialog sql results grid section
540544
:align: center

docs/en_US/query_tool.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,11 @@ very large result sets. However, they may offer lower performance in typical, ev
568568

569569
To enable server-side cursors:
570570

571-
* Go to Preferences > Query Tool > Options and set "Execute with server-side cursor?" to True.
572-
573-
.. image:: images/query_tool_server_cursor_preference.png
574-
:alt: Query Tool Manage Macros Clear row confirmation
575-
:align: center
576-
571+
* Go to Preferences > Query Tool > Options and set "Use server cursor?" to True.
577572
* Alternatively, you can enable it on a per-session basis via the Query Tool’s Execute menu.
578573

579574
.. image:: images/query_tool_server_cursor_execute_menu.png
580-
:alt: Query Tool Manage Macros Clear row confirmation
575+
:alt: Query Tool Server Cursor
581576
:align: center
582577

583578

web/pgadmin/static/js/components/PgTree/FileTreeItem/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen
134134
}
135135

136136
private readonly setActiveFile = async (FileOrDir): Promise<void> => {
137+
137138
this.props.changeDirectoryCount(FileOrDir.parent);
138139
if(FileOrDir._loaded !== true) {
139140
this.events.dispatch(FileTreeXEvent.onTreeEvents, window.event, 'added', FileOrDir);

web/pgadmin/static/js/tree/pgadmin_tree_save_state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/////////////////////////////////////////////////////////////
1+
l/////////////////////////////////////////////////////////////
22
//
33
// pgAdmin 4 - PostgreSQL Tools
44
//

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ def start_view_data(trans_id):
930930
status, result = conn.execute_async(
931931
sql,
932932
server_cursor=trans_obj.server_cursor)
933+
933934
else:
934935
status = False
935936
result = error_msg
@@ -1894,11 +1895,11 @@ def set_pref_options(trans_id, operation):
18941895

18951896
if operation == 'auto_commit':
18961897
# Call the set_auto_commit method of transaction object
1897-
trans_obj.set_auto_commit(_data)
1898+
trans_obj.set_auto_commit(_data['auto_commit'])
18981899
elif operation == 'auto_rollback':
1899-
trans_obj.set_auto_rollback(_data)
1900+
trans_obj.set_auto_rollback(_data['auto_rollback'])
19001901
elif operation == 'server_cursor':
1901-
trans_obj.set_server_cursor(_data)
1902+
trans_obj.set_server_cursor(_data['server_cursor'])
19021903

19031904
# As we changed the transaction object we need to
19041905
# restore it and update the session variable.
@@ -1933,7 +1934,7 @@ def set_auto_commit(trans_id):
19331934
@pga_login_required
19341935
def set_auto_rollback(trans_id):
19351936
"""
1936-
This method is used to set the value for auto commit .
1937+
This method is used to set the value for auto rollback .
19371938
19381939
Args:
19391940
trans_id: unique transaction id
@@ -1948,7 +1949,7 @@ def set_auto_rollback(trans_id):
19481949
@pga_login_required
19491950
def set_server_cursor(trans_id):
19501951
"""
1951-
This method is used to set the value for server_cursor.
1952+
This method is used to set the value for server cursor.
19521953
19531954
Args:
19541955
trans_id: unique transaction id

web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const StyledBox = styled(Box)(({theme}) => ({
4646
...theme.mixins.panelBorder.bottom,
4747
}));
4848

49-
function autoCommitRollback(type, api, transId, value) {
49+
function autoCommitRollbackServerCur(type, api, transId, value) {
5050
let url = url_for(`sqleditor.${type}`, {
5151
'trans_id': transId,
5252
});
@@ -127,7 +127,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
127127
queryToolCtx.updateServerCursor({server_cursor: newVal});
128128
}
129129
if(e.value === 'auto_commit' || e.value === 'auto_rollback' || e.value === 'server_cursor') {
130-
autoCommitRollback(e.value, queryToolCtx.api, queryToolCtx.params.trans_id, newVal)
130+
autoCommitRollbackServerCur(e.value, queryToolCtx.api, queryToolCtx.params.trans_id, newVal)
131131
.catch ((error)=>{
132132
newVal = prev[e.value];
133133
eventBus.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, error, {
@@ -267,8 +267,8 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
267267
};
268268
useEffect(()=>{
269269
if(isInTxn()) {
270-
setDisableButton('commit', false);
271-
setDisableButton('rollback', false);
270+
setDisableButton('commit', queryToolCtx.params.server_cursor && !queryToolCtx.params.is_query_tool ?true:false);
271+
setDisableButton('rollback', queryToolCtx.params.server_cursor && !queryToolCtx.params.is_query_tool ?true:false);
272272
setDisableButton('execute-options', true);
273273
} else {
274274
setDisableButton('commit', true);
@@ -639,7 +639,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
639639
<PgMenuItem hasCheck value="auto_rollback" checked={checkedMenuItems['auto_rollback']}
640640
onClick={checkMenuClick}>{gettext('Auto rollback on error?')}</PgMenuItem>
641641
<PgMenuItem hasCheck value="server_cursor" checked={checkedMenuItems['server_cursor']}
642-
onClick={checkMenuClick}>{gettext('Use server cursor')}</PgMenuItem>
642+
onClick={checkMenuClick}>{gettext('Use server cursor?')}</PgMenuItem>
643643
</PgMenu>
644644
<PgMenu
645645
anchorRef={explainMenuRef}

web/pgadmin/tools/sqleditor/static/js/components/sections/ResultSetToolbar.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ function PaginationInputs({pagination, totalRowCount, clearSelection, serverCurs
205205
/>
206206
</Box> : <span>{gettext('Showing rows: %s to %s', inputs.from, inputs.to)}</span>}
207207
<PgButtonGroup>
208-
{editPageRange && <PgIconButton size="xs"
208+
{!serverCursor && editPageRange && <PgIconButton size="xs"
209209
title={editPageRange ? gettext('Apply (or press Enter on input)') : gettext('Edit range')}
210210
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.FETCH_WINDOW, inputs.from, inputs.to)}
211211
disabled={errorInputs.from || errorInputs.to} icon={<CheckRoundedIcon />}
212212
/>}
213-
<PgIconButton size="xs"
213+
{!serverCursor && <PgIconButton size="xs"
214214
title={editPageRange ? gettext('Cancel edit') : gettext('Edit range')}
215215
onClick={()=>setEditPageRange((prev)=>!prev)}
216216
icon={editPageRange ? <EditOffRoundedIcon /> : <EditRoundedIcon />}
217-
/>
217+
/>}
218218
</PgButtonGroup>
219219
<div className='PaginationInputs-divider'>&nbsp;</div>
220220
<span>{gettext('Page No:')}</span>
@@ -228,13 +228,14 @@ function PaginationInputs({pagination, totalRowCount, clearSelection, serverCurs
228228
value={inputs.pageNo}
229229
onChange={(value)=>onInputChange('pageNo', value)}
230230
onKeyDown={onInputKeydownPageNo}
231+
disabled={serverCursor}
231232
error={errorInputs['pageNo']}
232233
/>
233234
<span> {gettext('of')} {pagination.page_count}</span>
234235
<div className='PaginationInputs-divider'>&nbsp;</div>
235236
<PgButtonGroup size="small">
236237
<PgIconButton title={gettext('First Page')} disabled={pagination.page_no <= 1 || serverCursor} onClick={()=>goToPage(1)} icon={<SkipPreviousRoundedIcon />}/>
237-
<PgIconButton title={gettext('Previous Page')} disabled={pagination.page_no <= 1 && !serverCursor} onClick={()=>goToPage(pagination.page_no-1)} icon={<FastRewindRoundedIcon />}/>
238+
<PgIconButton title={gettext('Previous Page')} disabled={pagination.page_no <= 1} onClick={()=>goToPage(pagination.page_no-1)} icon={<FastRewindRoundedIcon />}/>
238239
<PgIconButton title={gettext('Next Page')} disabled={pagination.page_no == pagination.page_count && !serverCursor} onClick={()=>goToPage(pagination.page_no+1)} icon={<FastForwardRoundedIcon />}/>
239240
<PgIconButton title={gettext('Last Page')} disabled={pagination.page_no == pagination.page_count || serverCursor} onClick={()=>goToPage(pagination.page_count)} icon={<SkipNextRoundedIcon />} />
240241
</PgButtonGroup>

web/pgadmin/tools/sqleditor/tests/test_server_cursor.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def setUp(self):
4040
secrets.choice(range(10000, 65535)))
4141
self._sid = self.server_information['server_id']
4242

43-
server_con = server_utils.connect_server(self, self._sid)
43+
server_utils.connect_server(self, self._sid)
4444

4545
self._did = test_utils.create_database(
4646
self.server, self._db_name
@@ -64,12 +64,10 @@ def initiate_sql_query_tool(self, trans_id, sql_query):
6464

6565
def set_server_cursor(self, server_cursor):
6666
_url = '/sqleditor/server_cursor/{0}'.format(self.trans_id)
67-
print(_url)
6867
res = self.tester.post(_url, data=json.dumps({
6968
"server_cursor": server_cursor
7069
}))
7170

72-
print(res)
7371
self.assertEqual(res.status_code, 200)
7472

7573
def runTest(self):
@@ -78,7 +76,7 @@ def runTest(self):
7876
test_utils.SERVER_GROUP,
7977
self._sid,
8078
self._did)
81-
if not db_con["info"] == "Database connected.":
79+
if db_con["info"] != "Database connected.":
8280
raise Exception("Could not connect to the database.")
8381

8482
# Initialize query tool
@@ -95,7 +93,8 @@ def runTest(self):
9593
response = self.initiate_sql_query_tool(self.trans_id, self.sql)
9694

9795
self.assertEqual(response.status_code, 200)
98-
csv_data = response.data.decode()
96+
_resp = response.data.decode()
97+
self.assertTrue(_resp.server_cursor)
9998

10099
self.set_server_cursor(False)
101100

web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ def register_query_tool_preferences(self):
8282

8383
self.server_cursor = self.preference.register(
8484
'Options', 'server_cursor',
85-
gettext("Execute with server side cursor?"), 'boolean', False,
85+
gettext("Use server cursor?"), 'boolean', False,
8686
category_label=PREF_LABEL_OPTIONS,
87-
help_str=gettext('If set to True, the dataset will be fetched from the'
88-
' server-side cursor after query execution.'
89-
' This will be helpful to transfer to the client only'
90-
' a controlled amount of data, so a large dataset can'
91-
' be examined without being kept entirely in memory.')
87+
help_str=gettext('If set to True, the dataset will be fetched using a'
88+
' server-side cursor after the query is executed.'
89+
' This allows controlled data transfer to the client,'
90+
' enabling examination of large datasets without'
91+
' loading them entirely into memory.')
9292
)
9393

9494
self.show_prompt_save_query_changes = self.preference.register(

0 commit comments

Comments
 (0)