Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Transform for loops into forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
CaroFG committed Jan 6, 2021
1 parent 458a627 commit ec3084a
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions setup/setup.js
Expand Up @@ -65,22 +65,17 @@ const rankingRulesDesc = [
apiKey: process.env.VUE_APP_MEILISEARCH_API_KEY
})

<<<<<<< HEAD
// Create Index or get the existing one
const index = await client.getOrCreateIndex('artWorks', { primaryKey: 'ObjectID' })

// Check if index has is populated
// Check if index is populated
const stats = await index.getStats()

if (stats.numberOfDocuments === dataset.length) {
console.log('Index "artWorks" is already populated')
return
}

=======
// Create Index
const index = await client.getOrCreateIndex('artWorks', { primaryKey: 'ObjectID' })
>>>>>>> 5f61ef8 (Remove unnecessary code)
console.log('Index "artWorks" created.')

// Add settings
Expand All @@ -93,12 +88,13 @@ const rankingRulesDesc = [
// Add documents
const batchedDataSet = batch(processedDataSet, 10000)
console.log('Adding documents...')
for (let i = 0; i < batchedDataSet.length; i++) {
const { updateId } = await index.addDocuments(batchedDataSet[i])
batchedDataSet.forEach(async (batch) => {
const { updateId } = await index.addDocuments(batch)
await index.waitForPendingUpdate(updateId, {
timeOutMs: 100000
})
}
})

console.log('Documents added to "artWorks" index.')

// ArtWorks with ASC order
Expand All @@ -108,12 +104,12 @@ const rankingRulesDesc = [
console.log('Settings added to "artWorksAsc" index.')

console.log('Adding documents...')
for (let i = 0; i < batchedDataSet.length; i++) {
const { updateId } = await indexAsc.addDocuments(batchedDataSet[i])
await indexAsc.waitForPendingUpdate(updateId, {
batchedDataSet.forEach(async (batch) => {
const { updateId } = await indexAsc.addDocuments(batch)
await index.waitForPendingUpdate(updateId, {
timeOutMs: 100000
})
}
})
console.log('Documents added to "artWorksAsc" index.')

// ArtWorks with DESC order
Expand All @@ -122,12 +118,12 @@ const rankingRulesDesc = [
await indexDesc.updateSettings(settings)
console.log('Settings added to "artWorksDesc" index.')
console.log('Adding documents...')
for (let i = 0; i < batchedDataSet.length; i++) {
const { updateId } = await indexDesc.addDocuments(batchedDataSet[i])
await indexDesc.waitForPendingUpdate(updateId, {
batchedDataSet.forEach(async (batch) => {
const { updateId } = await indexDesc.addDocuments(batch)
await index.waitForPendingUpdate(updateId, {
timeOutMs: 100000
})
}
})
console.log('Documents added to "artWorksDesc" index.')
})()

Expand Down

0 comments on commit ec3084a

Please sign in to comment.