ExportEtherpad: Process pad record separately

to improve readability.
This commit is contained in:
Richard Hansen 2022-04-13 04:21:15 -04:00
parent 56a60a34fb
commit 4a6e77839e
1 changed files with 13 additions and 17 deletions

View File

@ -22,24 +22,20 @@ const hooks = require('../../static/js/pluginfw/hooks');
exports.getPadRaw = async (padId, readOnlyId) => {
const keyPrefixRead = `pad:${padId}`;
const keyPrefixWrite = readOnlyId ? `pad:${readOnlyId}` : keyPrefixRead;
const padcontent = await db.get(keyPrefixRead);
const keySuffixes = [''];
for (let i = 0; i <= padcontent.head; i++) keySuffixes.push(`:revs:${i}`);
for (let i = 0; i <= padcontent.chatHead; i++) keySuffixes.push(`:chat:${i}`);
const data = {};
const data = {[keyPrefixWrite]: await db.get(keyPrefixRead)};
for (const [k, v] of Object.values(data[keyPrefixWrite].pool.numToAttrib)) {
if (k !== 'author') continue;
const authorEntry = await db.get(`globalAuthor:${v}`);
if (!authorEntry) continue;
data[`globalAuthor:${v}`] = authorEntry;
if (!authorEntry.padIDs) continue;
authorEntry.padIDs = readOnlyId || padId;
}
const keySuffixes = [];
for (let i = 0; i <= data[keyPrefixWrite].head; i++) keySuffixes.push(`:revs:${i}`);
for (let i = 0; i <= data[keyPrefixWrite].chatHead; i++) keySuffixes.push(`:chat:${i}`);
for (const keySuffix of keySuffixes) {
const entry = data[keyPrefixWrite + keySuffix] = await db.get(keyPrefixRead + keySuffix);
if (!entry.pool || !entry.pool.numToAttrib) continue;
for (const [k, v] of Object.values(entry.pool.numToAttrib)) {
if (k !== 'author') continue;
const authorEntry = await db.get(`globalAuthor:${v}`);
if (!authorEntry) continue;
data[`globalAuthor:${v}`] = authorEntry;
if (!authorEntry.padIDs) continue;
authorEntry.padIDs = readOnlyId || padId;
}
data[keyPrefixWrite + keySuffix] = await db.get(keyPrefixRead + keySuffix);
}
// get content that has a different prefix IE comments:padId:foo