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.
This commit is contained in:
Robin van Boven 2019-11-26 11:55:39 +01:00 committed by GitHub
parent 1e643d012f
commit a9e89b9f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 17 deletions

View File

@ -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");
}
}