sepia-search-motore-di-rice.../server/lib/meilisearch/meilisearch-instances.ts

31 lines
961 B
TypeScript
Raw Normal View History

2021-06-24 15:18:54 +02:00
import { CONFIG } from '../../initializers/constants'
2023-12-18 15:32:59 +01:00
import { listIndexInstancesHost, getMajorInstanceVersion } from '../requests/instances-index'
2023-12-18 14:48:40 +01:00
import { logger } from '../../helpers/logger'
2024-01-04 14:39:41 +01:00
import Bluebird from 'bluebird'
2020-02-19 15:39:35 +01:00
2024-01-09 11:06:15 +01:00
export async function buildInstanceHosts () {
2020-05-28 15:00:37 +02:00
let indexHosts = await listIndexInstancesHost()
2020-06-11 11:04:00 +02:00
if (CONFIG.INSTANCES_INDEX.WHITELIST.ENABLED) {
2020-09-03 14:25:57 +02:00
const whitelistHosts = Array.isArray(CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS)
? CONFIG.INSTANCES_INDEX.WHITELIST.HOSTS
: []
2020-05-28 15:00:37 +02:00
indexHosts = indexHosts.filter(h => whitelistHosts.includes(h))
}
2020-02-19 15:39:35 +01:00
2024-01-04 14:39:41 +01:00
indexHosts = await Bluebird.filter(indexHosts, async indexHost => {
2023-12-18 14:48:40 +01:00
const instanceVersion = await getMajorInstanceVersion(indexHost)
if (instanceVersion < 4) {
logger.info(`Do not index ${indexHost} because the major version is too low (v${instanceVersion} < v4)`)
2024-01-04 14:39:41 +01:00
return false
2023-12-18 14:48:40 +01:00
}
2024-01-04 14:39:41 +01:00
return true
}, { concurrency: 10 })
2023-12-18 14:48:40 +01:00
2024-01-09 11:06:15 +01:00
return indexHosts
2020-09-03 14:25:57 +02:00
}