Filter instance in bulk

This commit is contained in:
Chocobozzz 2024-01-04 14:39:41 +01:00
parent fde7007788
commit 69e17e2777
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 7 additions and 3 deletions

View File

@ -29,6 +29,7 @@ instances-index:
- 'replay.jres.org' - 'replay.jres.org'
- 'tube.nah.re' - 'tube.nah.re'
- 'video.passageenseine.fr' - 'video.passageenseine.fr'
- 'peertube.luga.at'
api: api:
blacklist: blacklist:

View File

@ -2,6 +2,7 @@ import { CONFIG } from '../../initializers/constants'
import { listIndexInstancesHost, getMajorInstanceVersion } from '../requests/instances-index' import { listIndexInstancesHost, getMajorInstanceVersion } from '../requests/instances-index'
import { client } from '../../helpers/meilisearch' import { client } from '../../helpers/meilisearch'
import { logger } from '../../helpers/logger' import { logger } from '../../helpers/logger'
import Bluebird from 'bluebird'
async function buildInstanceHosts () { async function buildInstanceHosts () {
let indexHosts = await listIndexInstancesHost() let indexHosts = await listIndexInstancesHost()
@ -14,16 +15,18 @@ async function buildInstanceHosts () {
indexHosts = indexHosts.filter(h => whitelistHosts.includes(h)) indexHosts = indexHosts.filter(h => whitelistHosts.includes(h))
} }
for (const indexHost of indexHosts) { indexHosts = await Bluebird.filter(indexHosts, async indexHost => {
const instanceVersion = await getMajorInstanceVersion(indexHost) const instanceVersion = await getMajorInstanceVersion(indexHost)
if (instanceVersion < 4) { if (instanceVersion < 4) {
logger.info(`Do not index ${indexHost} because the major version is too low (v${instanceVersion} < v4)`) logger.info(`Do not index ${indexHost} because the major version is too low (v${instanceVersion} < v4)`)
indexHosts = indexHosts.filter(h => h !== indexHost) return false
}
} }
return true
}, { concurrency: 10 })
const dbHosts = await listDBInstances() const dbHosts = await listDBInstances()
const removedHosts = getRemovedHosts(dbHosts, indexHosts) const removedHosts = getRemovedHosts(dbHosts, indexHosts)