Работа над WebWorker и DbCreator

This commit is contained in:
Book Pauk
2022-08-17 17:53:47 +07:00
parent 3cfb2beb3d
commit 38f63232a3
2 changed files with 16 additions and 18 deletions

View File

@@ -67,12 +67,18 @@ class InpxParser {
const structure = inpxStructure.split(';'); const structure = inpxStructure.split(';');
//парсим inp-файлы //парсим inp-файлы
this.chunk = [];
for (const inpFile of inpFiles) { for (const inpFile of inpFiles) {
await readFileCallback({fileName: inpFile, current: ++current}); await readFileCallback({fileName: inpFile, current: ++current});
const buf = await zipReader.extractToBuf(inpFile); const buf = await zipReader.extractToBuf(inpFile);
await this.parseInp(buf, structure, parsedCallback); await this.parseInp(buf, structure, parsedCallback);
} }
if (this.chunk.length) {
await parsedCallback(this.chunk);
}
} finally { } finally {
zipReader.close(); zipReader.close();
} }
@@ -82,7 +88,6 @@ class InpxParser {
const structLen = structure.length; const structLen = structure.length;
const rows = inpBuf.toString().split('\n'); const rows = inpBuf.toString().split('\n');
let chunk = [];
for (const row of rows) { for (const row of rows) {
let line = row; let line = row;
if (!line) if (!line)
@@ -117,17 +122,13 @@ class InpxParser {
rec.librate = parseInt(rec.librate, 10) || 0; rec.librate = parseInt(rec.librate, 10) || 0;
//пушим //пушим
chunk.push(rec); this.chunk.push(rec);
if (chunk.length >= 10000) { if (this.chunk.length >= 10000) {
await parsedCallback(chunk); await parsedCallback(this.chunk);
chunk = []; this.chunk = [];
} }
} }
if (chunk.length) {
await parsedCallback(chunk);
}
} }
get info() { get info() {

View File

@@ -63,7 +63,7 @@ class WebWorker {
async createDb(dbPath) { async createDb(dbPath) {
this.setMyState(ssDbCreating); this.setMyState(ssDbCreating);
log('Creating search DB'); log('Searcher DB create start');
const config = this.config; const config = this.config;
@@ -85,14 +85,11 @@ class WebWorker {
log(' start INPX import'); log(' start INPX import');
const dbCreator = new DbCreator(config); const dbCreator = new DbCreator(config);
let fileName = '';
await dbCreator.run(db, (state) => { await dbCreator.run(db, (state) => {
this.setMyState(ssDbCreating, state); this.setMyState(ssDbCreating, state);
if (state.fileName && state.fileName !== fileName) { if (state.fileName)
fileName = state.fileName; log(` load ${state.fileName}`);
log(` load ${fileName}`);
}
if (state.recsLoaded) if (state.recsLoaded)
log(` processed ${state.recsLoaded} records`); log(` processed ${state.recsLoaded} records`);
}); });
@@ -100,7 +97,7 @@ class WebWorker {
log(' finish INPX import'); log(' finish INPX import');
} finally { } finally {
await db.unlock(); await db.unlock();
log('Search DB created'); log('Searcher DB successfully created');
} }
} }
@@ -121,7 +118,7 @@ class WebWorker {
//загружаем БД //загружаем БД
this.setMyState(ssDbLoading); this.setMyState(ssDbLoading);
log('Open search DB'); log('Searcher DB open');
this.db = new JembaDbThread(); this.db = new JembaDbThread();
await this.db.lock({ await this.db.lock({
@@ -136,7 +133,7 @@ class WebWorker {
//открываем все таблицы //открываем все таблицы
await this.db.openAll(); await this.db.openAll();
log('Search DB ready'); log('Searcher DB is ready');
} catch (e) { } catch (e) {
log(LM_FATAL, e.message); log(LM_FATAL, e.message);
ayncExit.exit(1); ayncExit.exit(1);