@live-change/framework
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -102,59 +102,37 @@ const { typeName } = require("../utils.js") | ||
async function putAllData(modelName) { | ||
const db = await app.connectToDatabase() | ||
const index = generateIndexName(modelName) | ||
const cursor = await db.run( | ||
r.table(generateTableName(modelName)) | ||
) | ||
const table = generateTableName(modelName) | ||
const bucketSize = 256 | ||
let position = "" | ||
let more = true | ||
console.log(`INDEXING ${modelName}`) | ||
return new Promise((resolve, reject) => { | ||
let buffer = [] | ||
let readMore = () => {} | ||
let readFinished = false, writing = false | ||
cursor.eachAsync(function(row, rowFinished) { | ||
buffer.push(row) | ||
if(buffer.length < 1000) { | ||
buffer.push(row) | ||
rowFinished() | ||
} else { | ||
readMore = rowFinished | ||
console.log(`READED ${buffer.length} ROWS`) | ||
writeMore().catch(reject) | ||
} | ||
}, function() { | ||
readFinished = true | ||
console.log(`READED LAST ${buffer.length} ROWS`) | ||
if(buffer.length > 0) writeMore().catch(reject) | ||
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 | ||
}) | ||
async function writeMore() { | ||
if(writing) return; | ||
let data = buffer | ||
buffer = [] | ||
readMore() | ||
readMore = () => {} | ||
writing = true | ||
console.log(`WRITING ${data.length} ROWS`) | ||
let operations = new Array(data.length*2) | ||
for(let i = 0; i < data.length; i++) { | ||
operations[i * 2] = { index: { _id: data[i].id } } | ||
operations[i * 2 + 1] = data[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 | ||
}) | ||
writing = false | ||
if(buffer.length > 500) { | ||
writeMore().catch(reject) | ||
} else if(readFinished) { | ||
console.log(`WRITING FINISHED`) | ||
resolve(true) | ||
} | ||
} | ||
}) | ||
} while (more) | ||
} | ||
@@ -161,0 +139,0 @@ |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"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
108866
3020