This commit is contained in:
Jan Prochazka
2020-06-02 16:55:46 +02:00
parent c0188e866f
commit 7450b7fe85
3 changed files with 69 additions and 40 deletions

View File

@@ -37,6 +37,7 @@ module.exports = {
openReader(jslid) { openReader(jslid) {
// console.log('OPENING READER'); // console.log('OPENING READER');
console.log('OPENING READER, LINES=', fs.readFileSync(path.join(jsldir(), `${jslid}.jsonl`), 'utf-8').split('\n').length);
const file = path.join(jsldir(), `${jslid}.jsonl`); const file = path.join(jsldir(), `${jslid}.jsonl`);
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
lineReader.open(file, (err, reader) => { lineReader.open(file, (err, reader) => {
@@ -87,6 +88,7 @@ module.exports = {
}, },
async notifyChangedStats(stats) { async notifyChangedStats(stats) {
console.log('SENDING STATS', JSON.stringify(stats));
await this.closeReader(stats.jslid); await this.closeReader(stats.jslid);
socket.emit(`jsldata-stats-${stats.jslid}`, stats); socket.emit(`jsldata-stats-${stats.jslid}`, stats);
}, },

View File

@@ -13,28 +13,29 @@ let storedConnection;
let afterConnectCallbacks = []; let afterConnectCallbacks = [];
let currentHandlers = []; let currentHandlers = [];
class StreamHandler { class TableWriter {
constructor() { constructor(columns) {
this.recordset = this.recordset.bind(this); this.jslid = uuidv1();
this.row = this.row.bind(this); this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`);
// this.error = this.error.bind(this); this.currentStream = fs.createWriteStream(this.currentFile);
this.done = this.done.bind(this); this.currentRowCount = 0;
this.info = this.info.bind(this); this.currentChangeIndex = 0;
// use this for cancelling fs.writeFileSync(`${this.currentFile}.info`, JSON.stringify(columns));
this.stream = null; this.writeCurrentStats(false, false);
currentHandlers = [...currentHandlers, this]; process.send({ msgtype: 'recordset', jslid: this.jslid });
} }
closeCurrentStream() { row(row) {
if (this.currentStream) { // console.log('ACCEPT ROW', row);
this.currentStream.end(); this.currentStream.write(JSON.stringify(row) + '\n');
this.writeCurrentStats(true, true); this.currentRowCount += 1;
if (!this.plannedStats) {
this.currentStream = null; this.plannedStats = true;
this.jslid = null; process.nextTick(() => {
this.currentFile = null; if (this.currentStream) this.currentStream.uncork();
this.currentRowCount = null; process.nextTick(() => this.writeCurrentStats(false, true));
this.currentChangeIndex = null; this.plannedStats = false;
});
} }
} }
@@ -52,34 +53,57 @@ class StreamHandler {
} }
} }
recordset(columns) { close() {
this.closeCurrentStream(); if (this.currentStream) {
this.jslid = uuidv1(); this.currentStream.end(() => {
this.currentFile = path.join(jsldir(), `${this.jslid}.jsonl`); this.writeCurrentStats(true, true);
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); }
}
class StreamHandler {
constructor() {
this.recordset = this.recordset.bind(this);
this.row = this.row.bind(this);
// this.error = this.error.bind(this);
this.done = this.done.bind(this);
this.info = this.info.bind(this);
// use this for cancelling
this.stream = null;
this.plannedStats = false;
currentHandlers = [...currentHandlers, this];
}
closeCurrentWriter() {
if (this.currentWriter) {
this.currentWriter.close();
this.currentWriter = null;
}
}
recordset(columns) {
this.closeCurrentWriter();
this.currentWriter = new TableWriter(columns);
// this.writeCurrentStats();
// this.onRow = _.throttle((jslid) => {
// if (jslid == this.jslid) {
// this.writeCurrentStats(false, true);
// }
// }, 500);
} }
row(row) { row(row) {
// console.log('ACCEPT ROW', row); // console.log('ACCEPT ROW', row);
this.currentStream.write(JSON.stringify(row) + '\n'); this.currentWriter.row(row);
this.currentRowCount += 1; // this.onRow(this.jslid);
this.onRow(this.jslid);
} }
// error(error) { // error(error) {
// process.send({ msgtype: 'error', error }); // process.send({ msgtype: 'error', error });
// } // }
done(result) { done(result) {
this.closeCurrentStream(); this.closeCurrentWriter();
process.send({ msgtype: 'done', result }); process.send({ msgtype: 'done', result });
currentHandlers = currentHandlers.filter((x) => x != this); currentHandlers = currentHandlers.filter((x) => x != this);
} }

View File

@@ -208,6 +208,7 @@ export default function DataGridCore(props) {
loadedTime: new Date().getTime(), loadedTime: new Date().getTime(),
allRowCount: null, allRowCount: null,
errorMessage: null, errorMessage: null,
jslStatsCounter: 0,
}); });
const { isLoading, loadedRows, isLoadedAll, loadedTime, allRowCount, errorMessage } = loadProps; const { isLoading, loadedRows, isLoadedAll, loadedTime, allRowCount, errorMessage } = loadProps;
@@ -285,11 +286,11 @@ export default function DataGridCore(props) {
const loadedInfo = { const loadedInfo = {
loadedRows: [...loadedRows, ...nextRows], loadedRows: [...loadedRows, ...nextRows],
loadedTime, loadedTime,
isLoadedAll: nextRows.length === 0,
}; };
setLoadProps((oldLoadProps) => ({ setLoadProps((oldLoadProps) => ({
...oldLoadProps, ...oldLoadProps,
isLoading: false, isLoading: false,
isLoadedAll: oldLoadProps.jslStatsCounter == loadProps.jslStatsCounter && nextRows.length === 0,
...loadedInfo, ...loadedInfo,
})); }));
} }
@@ -375,6 +376,7 @@ export default function DataGridCore(props) {
isLoadedAll: false, isLoadedAll: false,
loadedTime: new Date().getTime(), loadedTime: new Date().getTime(),
errorMessage: null, errorMessage: null,
jslStatsCounter: 0,
}); });
}; };
@@ -419,6 +421,7 @@ export default function DataGridCore(props) {
...oldProps, ...oldProps,
allRowCount: stats.rowCount, allRowCount: stats.rowCount,
isLoadedAll: false, isLoadedAll: false,
jslStatsCounter: oldProps.jslStatsCounter + 1,
})); }));
}, []); }, []);