From 6a8563eeab0b2f9f31ca24b2e6739bc46239703d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 10 Nov 2020 01:20:05 -0500 Subject: [PATCH] import/export: Simplify exportEtherpadAdditionalContent processing Also: * Improve parallelization * Refine the documentation --- doc/api/hooks_server-side.md | 16 ++++++++++------ src/node/utils/ExportEtherpad.js | 18 +++++++----------- src/node/utils/ImportEtherpad.js | 16 +++++----------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index e1cfdfb7..6d380cf0 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -770,18 +770,22 @@ exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){ ``` ## exportEtherpadAdditionalContent -Called from src/node/utils/ExportEtherpad.js and src/node/utils/ImportEtherpad.js +Called from src/node/utils/ExportEtherpad.js and +src/node/utils/ImportEtherpad.js -Things in context: +Things in context: Nothing -Useful for exporting and importing non-pad centric data stored about a pad. For example in ep_comments_page the comments are stored as comments:padId:uniqueIdOfComment and as such when you export .etherpad this data is not included. +Useful for exporting and importing pad metadata that is stored in the database +but not in the pad's content or attributes. For example, in ep_comments_page the +comments are stored as `comments:padId:uniqueIdOfComment` so a complete export +of all pad data to an `.etherpad` file must include the `comments:padId:*` +records. Example: + ``` // Add support for exporting comments metadata -exports.exportEtherpadAdditionalContent = function(hook_name, context, callback){ - return callback(["comments"]); -}; +exports.exportEtherpadAdditionalContent = () => ['comments']; ``` ## userLeave diff --git a/src/node/utils/ExportEtherpad.js b/src/node/utils/ExportEtherpad.js index 2af4f7bf..a92a9192 100644 --- a/src/node/utils/ExportEtherpad.js +++ b/src/node/utils/ExportEtherpad.js @@ -59,17 +59,13 @@ exports.getPadRaw = async function(padId) { } } - await Promise.all([ - // get content that has a different prefix IE comments:padId:foo - // a plugin would return something likle ["comments", "cakes"] - hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => { - prefixes.forEach(async function(prefix) { - let pluginContent = await db.get(prefix + ":" + padId); - data[prefix + ":" + padId] = pluginContent; - }); - }) - ]); - + // get content that has a different prefix IE comments:padId:foo + // a plugin would return something likle ['comments', 'cakes'] + const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent'); + await Promise.all(prefixes.map(async (prefix) => { + const key = `${prefix}:${padId}`; + data[key] = await db.get(key); + })); return data; } diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index 1a61efac..27eae473 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -65,17 +65,11 @@ exports.setPadRaw = function(padId, records) } // is this a key that is supported through a plugin? - await Promise.all([ - // get content that has a different prefix IE comments:padId:foo - // a plugin would return something likle ["comments", "cakes"] - hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => { - prefixes.forEach(async function(prefix) { - if(key.split(":")[0] === prefix){ - newKey = prefix + ":" + padId; - } - }); - }) - ]); + // get content that has a different prefix IE comments:padId:foo + // a plugin would return something likle ['comments', 'cakes'] + for (const prefix of await hooks.aCallAll('exportEtherpadAdditionalContent')) { + if (prefix === oldPadId[0]) newKey = `${prefix}:${padId}`; + } } // Write the value to the server