mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-17 06:56:36 +00:00
mirror: make a data interface (#1291)
This is a quick fixup so that the coming createGraph module can be properly tested. Shout out to @Beanow for anticipating this need in a [review comment]. [review comment]: https://github.com/sourcecred/sourcecred/pull/1266#discussion_r314305108 Test plan: trivial refactor, run `yarn test`
This commit is contained in:
parent
2f8e1c61e4
commit
69831d6961
@ -15,6 +15,38 @@ import {
|
||||
// so that the cache will be properly invalidated.
|
||||
const VERSION = "discourse_mirror_v1";
|
||||
|
||||
/**
|
||||
* An interface for retrieving all of the Discourse data at once.
|
||||
*
|
||||
* Also has some convenience methods for interpeting the data (e.g. getting
|
||||
* a post by its index in a topic).
|
||||
*
|
||||
* The mirror implements this; it's factored out as an interface for
|
||||
* ease of testing.
|
||||
*/
|
||||
export interface DiscourseData {
|
||||
/**
|
||||
* Retrieve every Topic available.
|
||||
*
|
||||
* The order is unspecified.
|
||||
*/
|
||||
topics(): $ReadOnlyArray<Topic>;
|
||||
|
||||
/**
|
||||
* Retrieve every Post available.
|
||||
*
|
||||
* The order is unspecified.
|
||||
*/
|
||||
posts(): $ReadOnlyArray<Post>;
|
||||
|
||||
/**
|
||||
* Given a TopicId and a post number, find that numbered post within the topic.
|
||||
*
|
||||
* Returns undefined if no such post is available.
|
||||
*/
|
||||
findPostInTopic(topicId: TopicId, indexWithinTopic: number): ?PostId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors data from the Discourse API into a local sqlite db.
|
||||
*
|
||||
@ -32,7 +64,7 @@ const VERSION = "discourse_mirror_v1";
|
||||
* Each Mirror instance is tied to a particular server. Trying to use a mirror
|
||||
* for multiple Discourse servers is not permitted; use separate Mirrors.
|
||||
*/
|
||||
export class Mirror {
|
||||
export class Mirror implements DiscourseData {
|
||||
+_db: Database;
|
||||
+_fetcher: Discourse;
|
||||
|
||||
@ -168,11 +200,6 @@ export class Mirror {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a TopicId and a post number, find that numbered post within the topic.
|
||||
*
|
||||
* Returns undefined if no such post exists.
|
||||
*/
|
||||
findPostInTopic(topicId: TopicId, indexWithinTopic: number): ?PostId {
|
||||
return this._db
|
||||
.prepare(
|
||||
|
Loading…
x
Reference in New Issue
Block a user