Compare commits

...

2 Commits

Author SHA1 Message Date
Chocobozzz aaad2ea75d
Fix removing non existing hosts 2024-01-09 11:06:15 +01:00
Chocobozzz bf63503e23
More logs 2024-01-09 10:44:05 +01:00
3 changed files with 9 additions and 42 deletions

View File

@ -74,9 +74,9 @@ export abstract class AbstractIndexer <T extends IndexableDoc, DB> {
})
}
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))
})
}

View File

@ -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<string>()
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
}

View File

@ -56,16 +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({ 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 %s hosts', indexHosts.length)
await Bluebird.map(indexHosts, async host => {
await Bluebird.map(this.indexedHosts, async host => {
try {
await this.indexHost(host)
} catch (err) {