Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@live-change/framework

Package Overview
Dependencies
Maintainers
1
Versions
302
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@live-change/framework - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

82

lib/updaters/elasticsearch.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc