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
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

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
// 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;
}

View file

@ -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