Merge branch 'master' into meilisearch

This commit is contained in:
Chocobozzz 2023-12-18 15:32:59 +01:00
commit b98aa43a77
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 25 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import { CONFIG } from '../../initializers/constants' import { CONFIG } from '../../initializers/constants'
import { listIndexInstancesHost } 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'
async function buildInstanceHosts () { async function buildInstanceHosts () {
let indexHosts = await listIndexInstancesHost() let indexHosts = await listIndexInstancesHost()
@ -13,6 +14,16 @@ async function buildInstanceHosts () {
indexHosts = indexHosts.filter(h => whitelistHosts.includes(h)) indexHosts = indexHosts.filter(h => whitelistHosts.includes(h))
} }
for (const indexHost of indexHosts) {
const instanceVersion = await getMajorInstanceVersion(indexHost)
if (instanceVersion < 4) {
logger.info(`Do not index ${indexHost} because the major version is too low (v${instanceVersion} < v4)`)
indexHosts = indexHosts.filter(h => h !== indexHost)
}
}
const dbHosts = await listDBInstances() const dbHosts = await listDBInstances()
const removedHosts = getRemovedHosts(dbHosts, indexHosts) const removedHosts = getRemovedHosts(dbHosts, indexHosts)

View File

@ -1,7 +1,7 @@
import { CONFIG } from '../../initializers/constants' import { CONFIG } from '../../initializers/constants'
import { doRequest } from '../../helpers/requests' import { doRequest } from '../../helpers/requests'
async function listIndexInstancesHost (): Promise<string[]> { export async function listIndexInstancesHost (): Promise<string[]> {
const uri = CONFIG.INSTANCES_INDEX.URL const uri = CONFIG.INSTANCES_INDEX.URL
const qs = { const qs = {
@ -14,6 +14,14 @@ async function listIndexInstancesHost (): Promise<string[]> {
return body.data.map(o => o.host as string) return body.data.map(o => o.host as string)
} }
export { export async function getMajorInstanceVersion (host: string): Promise<number> {
listIndexInstancesHost const { body } = await doRequest<any>({ uri: `https://${host}/api/v1/config`, json: true })
const version = body.serverVersion
const majorVersion = parseInt(version.split('.')[0])
return isNaN(majorVersion)
? 0
: majorVersion
} }

View File

@ -55,7 +55,6 @@ async function getVideos (host: string, start: number): Promise<IndexableVideo[]
uri: url, uri: url,
qs: { qs: {
start, start,
filter: 'local', // Deprecated filter for old PeerTube instances
isLocal: true, isLocal: true,
nsfw: 'both', nsfw: 'both',
skipCount: true, skipCount: true,

View File

@ -63,6 +63,8 @@ export class IndexationScheduler extends AbstractScheduler {
await o.removeFromHosts(removedHosts) await o.removeFromHosts(removedHosts)
} }
logger.info({ indexHosts }, 'Will index %s hosts', indexHosts.length)
await Bluebird.map(indexHosts, async host => { await Bluebird.map(indexHosts, async host => {
try { try {
await this.indexHost(host) await this.indexHost(host)