feat: rebuild tree on page update

pull/1098/head
NGPixel 5 years ago
parent 62d1d7a1df
commit 73c89dfe44

@ -263,12 +263,7 @@ module.exports = {
*/
async rebuildTree(obj, args, context) {
try {
const rebuildJob = await WIKI.scheduler.registerJob({
name: 'rebuild-tree',
immediate: true,
worker: true
})
await rebuildJob.finished
await WIKI.models.pages.rebuildTree()
return {
responseResult: graphHelper.generateSuccess('Page tree rebuilt successfully.')
}

@ -10,7 +10,6 @@ module.exports = async (pageId) => {
await WIKI.configSvc.loadFromDb()
await WIKI.configSvc.applyFlags()
await WIKI.models.knex.table('pageTree').truncate()
const pages = await WIKI.models.pages.query().select('id', 'path', 'localeCode', 'title', 'isPrivate', 'privateNS').orderBy(['localeCode', 'path'])
let tree = []
let pik = 0
@ -52,6 +51,7 @@ module.exports = async (pageId) => {
}
}
await WIKI.models.knex.table('pageTree').truncate()
if (tree.length > 0) {
await WIKI.models.knex.table('pageTree').insert(tree)
}

@ -270,6 +270,9 @@ module.exports = class Page extends Model {
// -> Render page to HTML
await WIKI.models.pages.renderPage(page)
// -> Rebuild page tree
await WIKI.models.pages.rebuildTree()
// -> Add to Search Index
const pageContents = await WIKI.models.pages.query().findById(page.id).select('render')
page.safeContent = WIKI.models.pages.cleanHTML(pageContents.render)
@ -370,6 +373,11 @@ module.exports = class Page extends Model {
destinationPath: opts.path,
user: opts.user
})
} else {
// -> Update title of page tree entry
await WIKI.models.knex.table('pageTree').where({
pageId: page.id
}).update('title', page.title)
}
return page
@ -427,6 +435,9 @@ module.exports = class Page extends Model {
}).findById(page.id)
await WIKI.models.pages.deletePageFromCache(page)
// -> Rebuild page tree
await WIKI.models.pages.rebuildTree()
// -> Rename in Search Index
await WIKI.data.searchEngine.renamed({
...page,
@ -499,6 +510,9 @@ module.exports = class Page extends Model {
await WIKI.models.pages.query().delete().where('id', page.id)
await WIKI.models.pages.deletePageFromCache(page)
// -> Rebuild page tree
await WIKI.models.pages.rebuildTree()
// -> Delete from Search Index
await WIKI.data.searchEngine.deleted(page)
@ -519,14 +533,14 @@ module.exports = class Page extends Model {
}
/**
* Reconnect links to new/updated/deleted page
* Reconnect links to new/move/deleted page
*
* @param {Object} opts - Page parameters
* @param {string} opts.path - Page Path
* @param {string} opts.locale - Page Locale Code
* @param {string} [opts.sourcePath] - Previous Page Path (move only)
* @param {string} [opts.sourceLocale] - Previous Page Locale Code (move only)
* @param {string} opts.mode - Page Update mode (new, move, delete)
* @param {string} opts.mode - Page Update mode (create, move, delete)
* @returns {Promise} Promise with no value
*/
static async reconnectLinks (opts) {
@ -595,6 +609,20 @@ module.exports = class Page extends Model {
}
}
/**
* Rebuild page tree for new/updated/deleted page
*
* @returns {Promise} Promise with no value
*/
static async rebuildTree() {
const rebuildJob = await WIKI.scheduler.registerJob({
name: 'rebuild-tree',
immediate: true,
worker: true
})
return rebuildJob.finished
}
/**
* Trigger the rendering of a page
*

Loading…
Cancel
Save