query fixes

This commit is contained in:
Jan Prochazka 2020-04-12 10:55:41 +02:00
parent 6da41bcf4a
commit 241d8ea647
7 changed files with 38 additions and 10 deletions

View File

@ -22,7 +22,10 @@ module.exports = {
if (!this.openedReaders[jslid]) return Promise.reject();
return new Promise((resolve, reject) => {
const { reader } = this.openedReaders[jslid];
if (!reader.hasNextLine()) return Promise.resolve(null);
if (!reader.hasNextLine()) {
resolve(null);
return;
}
reader.nextLine((err, line) => {
this.openedReaders[jslid].readedCount += 1;
if (err) reject(err);
@ -66,7 +69,6 @@ module.exports = {
getRows_meta: 'get',
async getRows({ jslid, offset, limit }) {
// console.log('GET ROWS', offset, limit);
await this.ensureReader(jslid, offset);
const res = [];
for (let i = 0; i < limit; i += 1) {

View File

@ -27,7 +27,7 @@ async function handleConnect(connection) {
const driver = engines(storedConnection);
systemConnection = await driverConnect(driver, storedConnection);
handleFullRefresh();
setInterval(handleIncrementalRefresh, 10 * 1000);
setInterval(handleIncrementalRefresh, 30 * 1000);
for (const [resolve] of afterConnectCallbacks) {
resolve();
}

View File

@ -75,6 +75,7 @@ export default function MessagesView({ items, onMessageClick }) {
<StyledHeader>Message</StyledHeader>
<StyledHeader>Time</StyledHeader>
<StyledHeader>Delta</StyledHeader>
<StyledHeader>Duration</StyledHeader>
<StyledHeader>Procedure</StyledHeader>
<StyledHeader>Line</StyledHeader>
</tr>
@ -85,6 +86,11 @@ export default function MessagesView({ items, onMessageClick }) {
<StyledCell>{row.message}</StyledCell>
<StyledCell>{moment(row.time).format('HH:mm:ss')}</StyledCell>
<StyledCell>{formatDuration(new Date(row.time).getTime() - time0)}</StyledCell>
<StyledCell>
{index > 0
? formatDuration(new Date(row.time).getTime() - new Date(items[index - 1].time).getTime())
: 'n/a'}
</StyledCell>
<StyledCell>{row.procedure}</StyledCell>
<StyledCell>{row.line}</StyledCell>
</StyledRow>

View File

@ -2,12 +2,16 @@ import React from 'react';
import MessagesView from './MessagesView';
import useSocket from '../utility/SocketProvider';
export default function SessionMessagesView({ sessionId, onMessageClick }) {
export default function SessionMessagesView({ sessionId, onMessageClick, executeNumber }) {
const [messages, setMessages] = React.useState([]);
const socket = useSocket();
const handleInfo = React.useCallback((info) => setMessages((items) => [...items, info]), []);
React.useEffect(() => {
setMessages([]);
}, [executeNumber]);
React.useEffect(() => {
if (sessionId && socket) {
socket.on(`session-info-${sessionId}`, handleInfo);

View File

@ -3,7 +3,7 @@ import { TabPage, TabControl } from '../widgets/TabControl';
import useSocket from '../utility/SocketProvider';
import JslDataGrid from './JslDataGrid';
export default function ResultTabs({ children, sessionId }) {
export default function ResultTabs({ children, sessionId, executeNumber }) {
const socket = useSocket();
const [resultIds, setResultIds] = React.useState([]);
@ -12,6 +12,10 @@ export default function ResultTabs({ children, sessionId }) {
setResultIds((ids) => [...ids, jslid]);
};
React.useEffect(() => {
setResultIds([]);
}, [executeNumber]);
React.useEffect(() => {
if (sessionId && socket) {
socket.on(`session-recordset-${sessionId}`, handleResultSet);
@ -22,7 +26,7 @@ export default function ResultTabs({ children, sessionId }) {
}, [sessionId, socket]);
return (
<TabControl>
<TabControl activePageIndex={resultIds.length > 0 ? 1 : 0}>
{children}
{resultIds.map((jslid, index) => (
<TabPage label={`Result ${index + 1}`} key={index}>

View File

@ -10,6 +10,7 @@ import SessionMessagesView from '../query/SessionMessagesView';
import { TabPage } from '../widgets/TabControl';
import ResultTabs from '../sqleditor/ResultTabs';
import { VerticalSplitter } from '../widgets/Splitter';
import keycodes from '../utility/keycodes';
// const MainContainer = styled.div``;
@ -27,6 +28,7 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
const [queryText, setQueryText] = React.useState(() => localStorage.getItem(localStorageKey) || '');
const queryTextRef = React.useRef(queryText);
const [sessionId, setSessionId] = React.useState(null);
const [executeNumber, setExecuteNumber] = React.useState(0);
const saveToStorage = React.useCallback(() => localStorage.setItem(localStorageKey, queryTextRef.current), [
localStorageKey,
@ -54,6 +56,7 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
};
const handleExecute = async () => {
setExecuteNumber((num) => num + 1);
let sesid = sessionId;
if (!sesid) {
const resp = await axios.post('sessions/create', {
@ -69,7 +72,12 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
});
};
const handleKeyDown = () => {};
const handleKeyDown = (data, hash, keyString, keyCode, event) => {
if (keyCode == keycodes.f5) {
event.preventDefault();
handleExecute();
}
};
const handleMesageClick = (message) => {
// console.log('EDITOR', editorRef.current.editor);
@ -89,9 +97,9 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
onKeyDown={handleKeyDown}
editorRef={editorRef}
/>
<ResultTabs sessionId={sessionId}>
<ResultTabs sessionId={sessionId} executeNumber={executeNumber}>
<TabPage label="Messages" key="messages">
<SessionMessagesView sessionId={sessionId} onMessageClick={handleMesageClick} />
<SessionMessagesView sessionId={sessionId} onMessageClick={handleMesageClick} executeNumber={executeNumber} />
</TabPage>
</ResultTabs>
</VerticalSplitter>

View File

@ -61,13 +61,17 @@ export function TabPage({ key, label, children }) {
return children;
}
export function TabControl({ children }) {
export function TabControl({ children, activePageIndex = undefined }) {
const [value, setValue] = React.useState(0);
// const [mountedTabs, setMountedTabs] = React.useState({});
const childrenArray = (_.isArray(children) ? _.flatten(children) : [children]).filter((x) => x);
React.useEffect(() => {
if (activePageIndex != null) setValue(activePageIndex);
}, [activePageIndex]);
// // cleanup closed tabs
// if (_.difference(_.keys(mountedTabs), _.map(childrenArray, 'props.key')).length > 0) {
// setMountedTabs(_.pickBy(mountedTabs, (v, k) => childrenArray.find((x) => x.props.key == k)));