mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1004 B
36 lines
1004 B
import { pipeline } from 'node:stream/promises'
|
|
import { Transform } from 'node:stream'
|
|
|
|
export async function task ({ payload }) {
|
|
WIKI.logger.info('Rebuilding search index...')
|
|
|
|
try {
|
|
await WIKI.ensureDb()
|
|
|
|
let idx = 0
|
|
await pipeline(
|
|
WIKI.db.knex.select('id', 'title', 'description', 'locale', 'render', 'password').from('pages').stream(),
|
|
new Transform({
|
|
objectMode: true,
|
|
transform: async (page, enc, cb) => {
|
|
idx++
|
|
await WIKI.db.pages.updatePageSearchVector({ page })
|
|
if (idx % 50 === 0) {
|
|
WIKI.logger.info(`Rebuilding search index... (${idx} processed)`)
|
|
}
|
|
cb()
|
|
}
|
|
})
|
|
)
|
|
|
|
WIKI.logger.info('Refreshing autocomplete index...')
|
|
await WIKI.db.pages.refreshAutocompleteIndex()
|
|
|
|
WIKI.logger.info('Rebuilt search index: [ COMPLETED ]')
|
|
} catch (err) {
|
|
WIKI.logger.error('Rebuilding search index: [ FAILED ]')
|
|
WIKI.logger.error(err.message)
|
|
throw err
|
|
}
|
|
}
|