diff --git a/packages/api/src/controllers/archive.js b/packages/api/src/controllers/archive.js index 4e61d5fe..8beb1633 100644 --- a/packages/api/src/controllers/archive.js +++ b/packages/api/src/controllers/archive.js @@ -9,6 +9,7 @@ const getJslFileName = require('../utility/getJslFileName'); const { getLogger } = require('dbgate-tools'); const uuidv1 = require('uuid/v1'); const dbgateApi = require('../shell'); +const jsldata = require('./jsldata'); const logger = getLogger('archive'); @@ -109,6 +110,7 @@ module.exports = { saveChangeSet_meta: true, async saveChangeSet({ folder, file, changeSet }) { + await jsldata.closeDataStore(`archive://${folder}/${file}`); const changedFilePath = path.join(resolveArchiveFolder(folder), `${file}.jsonl`); const tmpchangedFilePath = path.join(resolveArchiveFolder(folder), `${file}-${uuidv1()}.jsonl`); const reader = await dbgateApi.changeSetOverJsonLinesReader({ fileName: changedFilePath, changeSet }); diff --git a/packages/api/src/controllers/jsldata.js b/packages/api/src/controllers/jsldata.js index e22a8ad5..d591c43d 100644 --- a/packages/api/src/controllers/jsldata.js +++ b/packages/api/src/controllers/jsldata.js @@ -113,6 +113,14 @@ module.exports = { return datastore; }, + async closeDataStore(jslid) { + const datastore = this.datastores[jslid]; + if (datastore) { + await datastore._closeReader(); + delete this.datastores[jslid]; + } + }, + getInfo_meta: true, async getInfo({ jslid }) { const file = getJslFileName(jslid); diff --git a/packages/api/src/utility/JsonLinesDatastore.js b/packages/api/src/utility/JsonLinesDatastore.js index e1dadbcf..b7f9c109 100644 --- a/packages/api/src/utility/JsonLinesDatastore.js +++ b/packages/api/src/utility/JsonLinesDatastore.js @@ -75,6 +75,7 @@ class JsonLinesDatastore { } _closeReader() { + // console.log('CLOSING READER', this.reader); if (!this.reader) return; const reader = this.reader; this.reader = null; @@ -83,7 +84,7 @@ class JsonLinesDatastore { // this.firstRowToBeReturned = null; this.currentFilter = null; this.currentSort = null; - reader.close(() => {}); + return new Promise(resolve => reader.close(resolve)); } async notifyChanged(callback) { @@ -97,6 +98,8 @@ class JsonLinesDatastore { } async _openReader(fileName) { + // console.log('OPENING READER', fileName); + // console.log(fs.readFileSync(fileName, 'utf-8')); return new Promise((resolve, reject) => lineReader.open(fileName, (err, reader) => { if (err) reject(err); diff --git a/packages/web/src/tabs/ArchiveFileTab.svelte b/packages/web/src/tabs/ArchiveFileTab.svelte index 1e1be23a..5f43193b 100644 --- a/packages/web/src/tabs/ArchiveFileTab.svelte +++ b/packages/web/src/tabs/ArchiveFileTab.svelte @@ -18,6 +18,7 @@