sepia-search-motore-di-rice.../server/lib/indexers/channel-indexer.ts

32 lines
970 B
TypeScript
Raw Normal View History

2021-06-24 15:18:54 +02:00
import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/constants'
import { DBChannel, IndexableChannel } from '../../types/channel.model'
2021-07-28 13:25:39 +02:00
import { buildChannelsMapping, formatChannelForDB } from '../elastic-search/elastic-search-channels'
2021-06-24 15:18:54 +02:00
import { getChannel } from '../requests/peertube-instance'
import { AbstractIndexer } from './shared'
export class ChannelIndexer extends AbstractIndexer <IndexableChannel, DBChannel> {
constructor () {
super(CONFIG.ELASTIC_SEARCH.INDEXES.CHANNELS, formatChannelForDB)
this.indexQueue.drain(async () => {
logger.info('Refresh channels index.')
await this.refreshIndex()
})
}
async indexSpecificElement (host: string, name: string) {
const channel = await getChannel(host, name)
logger.info('Indexing specific channel %s@%s.', name, host)
return this.indexElements([ channel ], true)
}
2021-07-28 13:25:39 +02:00
buildMapping () {
return buildChannelsMapping()
}
2021-06-24 15:18:54 +02:00
}