diff --git a/server/lib/indexers/shared/abstract-indexer.ts b/server/lib/indexers/shared/abstract-indexer.ts index 9bdf41b..0ff8246 100644 --- a/server/lib/indexers/shared/abstract-indexer.ts +++ b/server/lib/indexers/shared/abstract-indexer.ts @@ -74,9 +74,9 @@ export abstract class AbstractIndexer { }) } - removeFromHosts (hosts: string[]) { + removeFromHosts (existingHosts: string[]) { return client.index(this.indexName).deleteDocuments({ - filter: 'host IN ' + buildInValuesArray(Array.from(hosts)) + filter: 'host NOT IN ' + buildInValuesArray(Array.from(existingHosts)) }) } diff --git a/server/lib/meilisearch/meilisearch-instances.ts b/server/lib/meilisearch/meilisearch-instances.ts index a13cad1..7bd7f52 100644 --- a/server/lib/meilisearch/meilisearch-instances.ts +++ b/server/lib/meilisearch/meilisearch-instances.ts @@ -1,10 +1,9 @@ import { CONFIG } from '../../initializers/constants' import { listIndexInstancesHost, getMajorInstanceVersion } from '../requests/instances-index' -import { client } from '../../helpers/meilisearch' import { logger } from '../../helpers/logger' import Bluebird from 'bluebird' -async function buildInstanceHosts () { +export async function buildInstanceHosts () { let indexHosts = await listIndexInstancesHost() if (CONFIG.INSTANCES_INDEX.WHITELIST.ENABLED) { @@ -27,36 +26,5 @@ async function buildInstanceHosts () { return true }, { concurrency: 10 }) - const dbHosts = await listDBInstances() - const removedHosts = getRemovedHosts(dbHosts, indexHosts) - - return { indexHosts, removedHosts } -} - -export { - buildInstanceHosts -} - -// ################################################## - -async function listDBInstances () { - const setResult = new Set() - const indexes = [ - CONFIG.MEILISEARCH.INDEXES.VIDEOS, - CONFIG.MEILISEARCH.INDEXES.CHANNELS - ] - - for (const index of indexes) { - const result = await client.index(index).searchForFacetValues({ facetName: 'host' }) - - for (const b of result.facetHits) { - setResult.add(b.value) - } - } - - return Array.from(setResult) -} - -function getRemovedHosts (dbHosts: string[], indexHosts: string[]) { - return dbHosts.filter(dbHost => indexHosts.includes(dbHost) === false) + return indexHosts } diff --git a/server/lib/schedulers/indexation-scheduler.ts b/server/lib/schedulers/indexation-scheduler.ts index a050c4a..1e66f35 100644 --- a/server/lib/schedulers/indexation-scheduler.ts +++ b/server/lib/schedulers/indexation-scheduler.ts @@ -56,18 +56,15 @@ export class IndexationScheduler extends AbstractScheduler { private async runIndexer () { logger.info('Running indexer.') - const { indexHosts, removedHosts } = await buildInstanceHosts() - this.indexedHosts = indexHosts + this.indexedHosts = await buildInstanceHosts() - logger.info({ removedHosts }, `Will remove ${removedHosts.length} hosts that do not exist anymore`) + logger.info({ indexHosts: this.indexedHosts }, `Will index ${this.indexedHosts.length} hosts and remove non existing hosts`) for (const o of this.indexers) { - await o.removeFromHosts(removedHosts) + await o.removeFromHosts(this.indexedHosts) } - logger.info({ indexHosts }, `Will index ${indexHosts.length} hosts`) - - await Bluebird.map(indexHosts, async host => { + await Bluebird.map(this.indexedHosts, async host => { try { await this.indexHost(host) } catch (err) {