import/export: Simplify exportEtherpadAdditionalContent processing

Also:
  * Improve parallelization
  * Refine the documentation
This commit is contained in:
Richard Hansen 2020-11-10 01:20:05 -05:00 committed by John McLear
parent 8c55a38582
commit 6a8563eeab
3 changed files with 22 additions and 28 deletions

View file

@ -770,18 +770,22 @@ exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){
``` ```
## exportEtherpadAdditionalContent ## 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: Example:
``` ```
// Add support for exporting comments metadata // Add support for exporting comments metadata
exports.exportEtherpadAdditionalContent = function(hook_name, context, callback){ exports.exportEtherpadAdditionalContent = () => ['comments'];
return callback(["comments"]);
};
``` ```
## userLeave ## userLeave

View file

@ -59,17 +59,13 @@ exports.getPadRaw = async function(padId) {
} }
} }
await Promise.all([ // get content that has a different prefix IE comments:padId:foo
// get content that has a different prefix IE comments:padId:foo // a plugin would return something likle ['comments', 'cakes']
// a plugin would return something likle ["comments", "cakes"] const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent');
hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => { await Promise.all(prefixes.map(async (prefix) => {
prefixes.forEach(async function(prefix) { const key = `${prefix}:${padId}`;
let pluginContent = await db.get(prefix + ":" + padId); data[key] = await db.get(key);
data[prefix + ":" + padId] = pluginContent; }));
});
})
]);
return data; return data;
} }

View file

@ -65,17 +65,11 @@ exports.setPadRaw = function(padId, records)
} }
// is this a key that is supported through a plugin? // is this a key that is supported through a plugin?
await Promise.all([ // get content that has a different prefix IE comments:padId:foo
// get content that has a different prefix IE comments:padId:foo // a plugin would return something likle ['comments', 'cakes']
// a plugin would return something likle ["comments", "cakes"] for (const prefix of await hooks.aCallAll('exportEtherpadAdditionalContent')) {
hooks.aCallAll('exportEtherpadAdditionalContent').then((prefixes) => { if (prefix === oldPadId[0]) newKey = `${prefix}:${padId}`;
prefixes.forEach(async function(prefix) { }
if(key.split(":")[0] === prefix){
newKey = prefix + ":" + padId;
}
});
})
]);
} }
// Write the value to the server // Write the value to the server