loading data from query fix

This commit is contained in:
Jan Prochazka
2020-04-14 21:18:43 +02:00
parent cc4eb133a7
commit 6e8ef35902
4 changed files with 81 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ const path = require('path');
const fs = require('fs');
const lineReader = require('line-reader');
const { jsldir } = require('../utility/directories');
const socket = require('../utility/socket');
module.exports = {
openedReaders: {},
@@ -78,4 +79,15 @@ module.exports = {
}
return res;
},
getStats_meta: 'get',
getStats({ jslid }) {
const file = path.join(jsldir(), `${jslid}.jsonl.stats`);
return JSON.parse(fs.readFileSync(file, 'utf-8'));
},
async notifyChangedStats(stats) {
await this.closeReader(stats.jslid);
socket.emit(`jsldata-stats-${stats.jslid}`, stats);
},
};

View File

@@ -3,6 +3,7 @@ const uuidv1 = require('uuid/v1');
const connections = require('./connections');
const socket = require('../utility/socket');
const { fork } = require('child_process');
const jsldata = require('./jsldata');
module.exports = {
/** @type {import('@dbgate/types').OpenedSession[]} */
@@ -53,6 +54,10 @@ module.exports = {
socket.emit(`session-recordset-${sesid}`, { jslid });
},
handle_stats(sesid, stats) {
jsldata.notifyChangedStats(stats);
},
create_meta: 'post',
async create({ conid, database }) {
const sesid = uuidv1();

View File

@@ -2,6 +2,7 @@ const engines = require('@dbgate/engines');
const uuidv1 = require('uuid/v1');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const driverConnect = require('../utility/driverConnect');
const { jsldir } = require('../utility/directories');
@@ -26,7 +27,27 @@ class StreamHandler {
closeCurrentStream() {
if (this.currentStream) {
this.currentStream.end();
this.writeCurrentStats(true, true);
this.currentStream = null;
this.jslid = null;
this.currentFile = null;
this.currentRowCount = null;
this.currentChangeIndex = null;
}
}
writeCurrentStats(isFinished = false, emitEvent = false) {
const stats = {
rowCount: this.currentRowCount,
changeIndex: this.currentChangeIndex,
isFinished,
jslid: this.jslid,
};
fs.writeFileSync(`${this.currentFile}.stats`, JSON.stringify(stats));
this.currentChangeIndex += 1;
if (emitEvent) {
process.send({ msgtype: 'stats', ...stats });
}
}
@@ -35,12 +56,23 @@ class StreamHandler {
this.jslid = uuidv1();
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
this.currentStream = fs.createWriteStream(this.currentFile);
this.currentRowCount = 0;
this.currentChangeIndex = 0;
fs.writeFileSync(`${this.currentFile}.info`, JSON.stringify(columns));
process.send({ msgtype: 'recordset', jslid: this.jslid });
this.writeCurrentStats();
this.onRow = _.throttle((jslid) => {
if (jslid == this.jslid) {
this.writeCurrentStats(false, true);
}
}, 500);
}
row(row) {
// console.log('ACCEPT ROW', row);
this.currentStream.write(JSON.stringify(row) + '\n');
this.currentRowCount += 1;
this.onRow(this.jslid);
}
// error(error) {
// process.send({ msgtype: 'error', error });