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

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
CaroFG committed Jan 11, 2021
1 parent 9fb394f commit f77b270
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions setup/setup.js
Expand Up @@ -84,12 +84,12 @@ const defaultRankingRules = [
const artWorksAscIndex = await client.getOrCreateIndex('artWorksAsc', { primaryKey: 'ObjectID' })
const artWorksDescIndex = await client.getOrCreateIndex('artWorksDesc', { primaryKey: 'ObjectID' })

// Check if index are populated and populate them is needed
const artWorks = { name: 'artWorks', index: artWorksIndex, rules: defaultRankingRules }
const artWorksAsc = { name: 'artWorksAsc', index: artWorksAscIndex, rules: rankingRulesAsc }
const artWorksDesc = { name: 'artWorksDesc', index: artWorksDescIndex, rules: rankingRulesDesc }

const indexArray = [artWorks, artWorksAsc, artWorksDesc]
// Create Indexes array
const indexArray = [
{ name: 'artWorks', index: artWorksIndex, rules: defaultRankingRules },
{ name: 'artWorksAsc', index: artWorksAscIndex, rules: rankingRulesAsc },
{ name: 'artWorksDesc', index: artWorksDescIndex, rules: rankingRulesDesc }
]

for (const index of indexArray) {
const isPopulated = await indexIsPopulated(index.index, dataset)
Expand Down Expand Up @@ -172,9 +172,5 @@ async function populateIndex ({ index, rules, name }, batchedDataSet) {

async function indexIsPopulated (index, dataset) {
const indexStats = await index.getStats()
if (indexStats.numberOfDocuments === dataset.length) {
return true
} else {
return false
}
return indexStats.numberOfDocuments === dataset.length
}

0 comments on commit f77b270

Please sign in to comment.