From a9e89b9f327fae58ef6a0459c862bdfdecfc9edd Mon Sep 17 00:00:00 2001 From: Robin van Boven <497556+Beanow@users.noreply.github.com> Date: Tue, 26 Nov 2019 11:55:39 +0100 Subject: [PATCH] Discourse: move update steps to separate functions (#1462) Makes no functional changes, it simply splits the update into separate functions so it can be switched out for another implementation. --- src/plugins/discourse/mirror.js | 40 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/plugins/discourse/mirror.js b/src/plugins/discourse/mirror.js index d5ff83a..b5b96ee 100644 --- a/src/plugins/discourse/mirror.js +++ b/src/plugins/discourse/mirror.js @@ -70,6 +70,13 @@ export class Mirror { } async update(reporter: TaskReporter) { + reporter.start("discourse"); + await this._updateTopics(reporter); + await this._updateLikes(reporter); + reporter.finish("discourse"); + } + + async _updateTopics(reporter: TaskReporter) { // Local functions add the warning and tracking semantics we want from them. const encounteredPostIds = new Set(); @@ -86,22 +93,6 @@ export class Mirror { } }; - const addLike = (like) => { - try { - const res = this._repo.addLike(like); - return {doneWithUser: res.changes === 0}; - } catch (e) { - console.warn( - `Warning: Encountered error '${e.message}' ` + - `on a like by ${like.username} ` + - `on post id ${like.postId}.` - ); - return {doneWithUser: false}; - } - }; - - reporter.start("discourse"); - const { maxPostId: lastLocalPostId, maxTopicId: lastLocalTopicId, @@ -148,6 +139,22 @@ export class Mirror { } } reporter.finish("discourse/posts"); + } + + async _updateLikes(reporter: TaskReporter) { + const addLike = (like) => { + try { + const res = this._repo.addLike(like); + return {doneWithUser: res.changes === 0}; + } catch (e) { + console.warn( + `Warning: Encountered error '${e.message}' ` + + `on a like by ${like.username} ` + + `on post id ${like.postId}.` + ); + return {doneWithUser: false}; + } + }; // I don't want to hard code the expected page size, in case it changes upstream. // However, it's helpful to have a good guess of what the page size is, because if we @@ -189,6 +196,5 @@ export class Mirror { } } reporter.finish("discourse/likes"); - reporter.finish("discourse"); } }