Compare commits

...

3 Commits

Author SHA1 Message Date
Chocobozzz 0a210321ea
Fix filter 2023-12-18 15:25:18 +01:00
Chocobozzz 67de789428
Fix v6 indexation 2023-12-18 14:48:40 +01:00
Chocobozzz 33c2c59460
Add indexation hosts log 2023-12-18 12:03:10 +01:00
4 changed files with 26 additions and 5 deletions

View File

@ -1,8 +1,9 @@
import { AggregationsStringTermsAggregate } from '@elastic/elasticsearch/lib/api/types'
import { elasticSearch } from '../../helpers/elastic-search'
import { CONFIG } from '../../initializers/constants'
import { listIndexInstancesHost } from '../requests/instances-index'
import { getMajorInstanceVersion, listIndexInstancesHost } from '../requests/instances-index'
import { extractBucketsFromAggregation } from './elastic-search-queries'
import { logger } from '../../helpers/logger'
async function buildInstanceHosts () {
let indexHosts = await listIndexInstancesHost()
@ -15,6 +16,16 @@ async function buildInstanceHosts () {
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 removedHosts = getRemovedHosts(dbHosts, indexHosts)

View File

@ -1,7 +1,7 @@
import { CONFIG } from '../../initializers/constants'
import { doRequest } from '../../helpers/requests'
async function listIndexInstancesHost (): Promise<string[]> {
export async function listIndexInstancesHost (): Promise<string[]> {
const uri = CONFIG.INSTANCES_INDEX.URL
const qs = {
@ -14,6 +14,14 @@ async function listIndexInstancesHost (): Promise<string[]> {
return body.data.map(o => o.host as string)
}
export {
listIndexInstancesHost
export async function getMajorInstanceVersion (host: string): Promise<number> {
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,
qs: {
start,
filter: 'local', // Deprecated filter for old PeerTube instances
isLocal: true,
nsfw: 'both',
skipCount: true,

View File

@ -10,6 +10,7 @@ import { PlaylistIndexer } from '../indexers/playlist-indexer'
import { VideoIndexer } from '../indexers/video-indexer'
import { getPlaylistsOf, getVideos } from '../requests/peertube-instance'
import { AbstractScheduler } from './abstract-scheduler'
import { getMajorInstanceVersion } from '../requests/instances-index'
export class IndexationScheduler extends AbstractScheduler {
@ -61,6 +62,8 @@ export class IndexationScheduler extends AbstractScheduler {
await o.removeFromHosts(removedHosts)
}
logger.info({ indexHosts }, 'Will index %s hosts', indexHosts.length)
await Bluebird.map(indexHosts, async host => {
try {
await this.indexHost(host)