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

View file

@ -22,17 +22,8 @@ const hooks = require('../../static/js/pluginfw/hooks');
exports.getPadRaw = async (padId, readOnlyId) => { exports.getPadRaw = async (padId, readOnlyId) => {
const keyPrefixRead = `pad:${padId}`; const keyPrefixRead = `pad:${padId}`;
const keyPrefixWrite = readOnlyId ? `pad:${readOnlyId}` : keyPrefixRead; const keyPrefixWrite = readOnlyId ? `pad:${readOnlyId}` : keyPrefixRead;
const padcontent = await db.get(keyPrefixRead); const data = {[keyPrefixWrite]: await db.get(keyPrefixRead)};
for (const [k, v] of Object.values(data[keyPrefixWrite].pool.numToAttrib)) {
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 = {};
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; if (k !== 'author') continue;
const authorEntry = await db.get(`globalAuthor:${v}`); const authorEntry = await db.get(`globalAuthor:${v}`);
if (!authorEntry) continue; if (!authorEntry) continue;
@ -40,6 +31,11 @@ exports.getPadRaw = async (padId, readOnlyId) => {
if (!authorEntry.padIDs) continue; if (!authorEntry.padIDs) continue;
authorEntry.padIDs = readOnlyId || padId; 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) {
data[keyPrefixWrite + keySuffix] = await db.get(keyPrefixRead + keySuffix);
} }
// get content that has a different prefix IE comments:padId:foo // get content that has a different prefix IE comments:padId:foo