Работа над WebWorker и DbCreator
This commit is contained in:
@@ -67,12 +67,18 @@ class InpxParser {
|
||||
const structure = inpxStructure.split(';');
|
||||
|
||||
//парсим inp-файлы
|
||||
this.chunk = [];
|
||||
for (const inpFile of inpFiles) {
|
||||
await readFileCallback({fileName: inpFile, current: ++current});
|
||||
const buf = await zipReader.extractToBuf(inpFile);
|
||||
|
||||
await this.parseInp(buf, structure, parsedCallback);
|
||||
}
|
||||
|
||||
if (this.chunk.length) {
|
||||
await parsedCallback(this.chunk);
|
||||
}
|
||||
|
||||
} finally {
|
||||
zipReader.close();
|
||||
}
|
||||
@@ -82,7 +88,6 @@ class InpxParser {
|
||||
const structLen = structure.length;
|
||||
const rows = inpBuf.toString().split('\n');
|
||||
|
||||
let chunk = [];
|
||||
for (const row of rows) {
|
||||
let line = row;
|
||||
if (!line)
|
||||
@@ -117,17 +122,13 @@ class InpxParser {
|
||||
rec.librate = parseInt(rec.librate, 10) || 0;
|
||||
|
||||
//пушим
|
||||
chunk.push(rec);
|
||||
this.chunk.push(rec);
|
||||
|
||||
if (chunk.length >= 10000) {
|
||||
await parsedCallback(chunk);
|
||||
chunk = [];
|
||||
if (this.chunk.length >= 10000) {
|
||||
await parsedCallback(this.chunk);
|
||||
this.chunk = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.length) {
|
||||
await parsedCallback(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
get info() {
|
||||
|
||||
@@ -63,7 +63,7 @@ class WebWorker {
|
||||
|
||||
async createDb(dbPath) {
|
||||
this.setMyState(ssDbCreating);
|
||||
log('Creating search DB');
|
||||
log('Searcher DB create start');
|
||||
|
||||
const config = this.config;
|
||||
|
||||
@@ -85,14 +85,11 @@ class WebWorker {
|
||||
log(' start INPX import');
|
||||
const dbCreator = new DbCreator(config);
|
||||
|
||||
let fileName = '';
|
||||
await dbCreator.run(db, (state) => {
|
||||
this.setMyState(ssDbCreating, state);
|
||||
|
||||
if (state.fileName && state.fileName !== fileName) {
|
||||
fileName = state.fileName;
|
||||
log(` load ${fileName}`);
|
||||
}
|
||||
if (state.fileName)
|
||||
log(` load ${state.fileName}`);
|
||||
if (state.recsLoaded)
|
||||
log(` processed ${state.recsLoaded} records`);
|
||||
});
|
||||
@@ -100,7 +97,7 @@ class WebWorker {
|
||||
log(' finish INPX import');
|
||||
} finally {
|
||||
await db.unlock();
|
||||
log('Search DB created');
|
||||
log('Searcher DB successfully created');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +118,7 @@ class WebWorker {
|
||||
|
||||
//загружаем БД
|
||||
this.setMyState(ssDbLoading);
|
||||
log('Open search DB');
|
||||
log('Searcher DB open');
|
||||
|
||||
this.db = new JembaDbThread();
|
||||
await this.db.lock({
|
||||
@@ -136,7 +133,7 @@ class WebWorker {
|
||||
//открываем все таблицы
|
||||
await this.db.openAll();
|
||||
|
||||
log('Search DB ready');
|
||||
log('Searcher DB is ready');
|
||||
} catch (e) {
|
||||
log(LM_FATAL, e.message);
|
||||
ayncExit.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user