From 92cd2cc760f369b14f48f0f3c3cf4feccf9568b1 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 9 Jan 2021 02:28:45 -0500 Subject: [PATCH] bin scripts: Use destructuring instead of long condition checks --- bin/checkAllPads.js | 4 ++-- bin/checkPad.js | 6 ++---- bin/checkPadDeltas.js | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bin/checkAllPads.js b/bin/checkAllPads.js index 8426d4429..063da96a5 100644 --- a/bin/checkAllPads.js +++ b/bin/checkAllPads.js @@ -66,13 +66,13 @@ npm.load({}, async () => { } // check if there is a atext in the keyRevisions - if (revisions[keyRev].meta == null || revisions[keyRev].meta.atext == null) { + let {meta: {atext} = {}} = revisions[keyRev]; + if (atext == null) { console.error(`[${pad.id}] Missing atext in revision ${keyRev}`); continue; } const apool = pad.pool; - let atext = revisions[keyRev].meta.atext; for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) { try { const cs = revisions[rev].changeset; diff --git a/bin/checkPad.js b/bin/checkPad.js index 374a3c856..42e5946c1 100644 --- a/bin/checkPad.js +++ b/bin/checkPad.js @@ -62,15 +62,13 @@ npm.load({}, async () => { if (pad.pool == null) throw new Error('Attribute pool is missing'); // check if there is an atext in the keyRevisions - if (revisions[keyRev] == null || - revisions[keyRev].meta == null || - revisions[keyRev].meta.atext == null) { + let {meta: {atext} = {}} = revisions[keyRev] || {}; + if (atext == null) { console.error(`No atext in key revision ${keyRev}`); continue; } const apool = pad.pool; - let atext = revisions[keyRev].meta.atext; for (let rev = keyRev + 1; rev <= keyRev + 100 && rev <= head; rev++) { checkRevisionCount++; diff --git a/bin/checkPadDeltas.js b/bin/checkPadDeltas.js index c53275a28..19d4ba4db 100644 --- a/bin/checkPadDeltas.js +++ b/bin/checkPadDeltas.js @@ -54,8 +54,8 @@ npm.load({}, async () => { // console.log('Fetching', revNum) const revision = await db.get(`pad:${padId}:revs:${revNum}`); // check if there is a atext in the keyRevisions - if (~keyRevisions.indexOf(revNum) && - (revision == null || revision.meta == null || revision.meta.atext == null)) { + const {meta: {atext: revAtext} = {}} = revision || {}; + if (~keyRevisions.indexOf(revNum) && revAtext == null) { console.error(`No atext in key revision ${revNum}`); continue; }