@live-change/framework
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -12,15 +12,11 @@ const utils = require("../utils.js") | ||
if (!model.search) continue | ||
const index = generateIndexName(modelName) | ||
model.searchIndex = index | ||
if(!model.onChange) model.onChange = [] | ||
model.onChange.push(async function(id, oldValue, newValue) { | ||
if(newValue) { // Update or Insert | ||
//console.log("SEARCH INSERT", index, id, JSON.stringify(newValue, null, ' ')) | ||
search.index({ index, id, body: newValue }) | ||
} else { | ||
search.delete({ index, id }) | ||
} | ||
}) | ||
const searchIndex = generateIndexName(modelName) | ||
model.searchIndex = searchIndex | ||
} | ||
for(let indexName in service.indexes) { | ||
const index = service.models[indexName] | ||
if (!index.search) continue | ||
const searchIndex = generateIndexName(indexName) | ||
model.searchIndex = searchIndex | ||
} | ||
} |
@@ -8,2 +8,3 @@ const Model = require("./Model.js") | ||
const TriggerHandler = require("./TriggerHandler.js") | ||
const SearchIndexer = require("./SearchIndexer.js") | ||
const ReactiveDao = require("@live-change/dao") | ||
@@ -77,5 +78,9 @@ | ||
if(config.runCommands) this.startCommandExecutor() | ||
if(config.handleEvents) this.startEventListener() | ||
let promises = [] | ||
if(config.runCommands) promises.push(this.startCommandExecutor()) | ||
if(config.handleEvents) promises.push(this.startEventListener()) | ||
if(config.indexSearch) promises.push(this.startSearchIndexer()) | ||
await Promise.all(promises) | ||
//if(config.startEventListener) this.startEventListener() | ||
@@ -205,2 +210,36 @@ | ||
async startSearchIndexer() { | ||
await this.dao.request(['database', 'createTable'], this.databaseName, 'searchIndexes').catch(e => 'ok') | ||
this.searchIndexers = [] | ||
const elasticsearch = this.app.connectToSearch() | ||
for(const modelName in this.models) { | ||
const model = this.models[modelName] | ||
const indexName = model.definition.searchIndex | ||
if(!indexName) continue | ||
const indexer = new SearchIndexer( | ||
this.dao, this.databaseName, 'Table', model.tableName, elasticsearch, indexName | ||
) | ||
this.searchIndexers.push(indexer) | ||
} | ||
for(const indexName in this.indexes) { | ||
const index = this.indexes[indexName] | ||
const indexName = index.definition.searchIndex | ||
if(!indexName) continue | ||
const indexer = new SearchIndexer( | ||
this.dao, this.databaseName, 'Index', model.tableName, elasticsearch, indexName | ||
) | ||
this.searchIndexers.push(indexer) | ||
} | ||
const promises = [] | ||
for(const searchIndexer of this.searchIndexers) { | ||
promises.push(searchIndexer.start()) | ||
} | ||
await Promise.all(promises) | ||
} | ||
} | ||
@@ -207,0 +246,0 @@ |
@@ -101,40 +101,2 @@ const { typeName } = require("../utils.js") | ||
async function putAllData(modelName) { | ||
const index = generateIndexName(modelName) | ||
const table = generateTableName(modelName) | ||
const bucketSize = 256 | ||
let position = "" | ||
let more = true | ||
console.log(`INDEXING ${modelName}`) | ||
do { | ||
const rows = await app.dao.get(['database', 'tableRange', app.databaseName, table, { | ||
gt: position, | ||
limit: bucketSize | ||
}]) | ||
position = rows.length ? rows[rows.length-1].id : "\xFF" | ||
more = (rows.length == bucketSize) | ||
if(more) console.log(`READED ${rows.length} ROWS`) | ||
else console.log(`READED LAST ${rows.length} ROWS`) | ||
console.log(`WRITING ${rows.length} ROWS`) | ||
let operations = new Array(rows.length*2) | ||
for(let i = 0; i < rows.length; i++) { | ||
operations[i * 2] = { index: { _id: rows[i].id } } | ||
operations[i * 2 + 1] = rows[i] | ||
} | ||
await search.bulk({ | ||
index, | ||
body: operations | ||
}).catch(error => { | ||
error = (error && error.meta && error.meta.body && error.meta.body.error) || error | ||
console.error("ES ERROR:", error) | ||
throw error | ||
}) | ||
} while (more) | ||
} | ||
async function setPropertyDefaultValue(currentAlias, propertyName, defaultValue) { | ||
@@ -197,3 +159,2 @@ const req = { | ||
}) | ||
await putAllData(change.model) | ||
} break | ||
@@ -200,0 +161,0 @@ case "deleteModel": |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Live Change Framework - ultimate solution for real time mobile/web apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115971
44
3222