From 2ca740c1db1b6051f3ec3c7f43f89fb3f689d021 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 27 Nov 2021 18:14:05 -0500 Subject: [PATCH] Pad: Improve readability of `appendRevision()` --- src/node/db/Pad.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 822f008b5..6e3fbf2c3 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -81,27 +81,24 @@ class Pad { const newRev = ++this.head; - const newRevData = {}; - newRevData.changeset = aChangeset; - newRevData.meta = {}; - newRevData.meta.author = authorId; - newRevData.meta.timestamp = Date.now(); - // ex. getNumForAuthor if (authorId !== '') this.pool.putAttrib(['author', authorId]); - if (newRev === this.getKeyRevisionNumber(newRev)) { - newRevData.meta.pool = this.pool; - newRevData.meta.atext = this.atext; - } - - const p = [ - this.db.set(`pad:${this.id}:revs:${newRev}`, newRevData), + const p = Promise.all([ + this.db.set(`pad:${this.id}:revs:${newRev}`, { + changeset: aChangeset, + meta: { + author: authorId, + timestamp: Date.now(), + ...newRev === this.getKeyRevisionNumber(newRev) ? { + pool: this.pool, + atext: this.atext, + } : {}, + }, + }), this.saveToDatabase(), - ]; - - // set the author to pad - if (authorId) p.push(authorManager.addPad(authorId, this.id)); + authorId && authorManager.addPad(authorId, this.id), + ]); let hook = 'padCreate'; const context = { @@ -123,7 +120,7 @@ class Pad { } hooks.callAll(hook, context); - await Promise.all(p); + await p; return newRev; }