From bbf5ef3f9324049aa0d1ef007270a47ade7c941e Mon Sep 17 00:00:00 2001 From: Shrivaths Shyam Date: Tue, 12 Dec 2023 17:06:04 -0800 Subject: [PATCH 1/7] Limit the number of posts in mastodon --- src/scripts/fetchers/MastodonFetcher.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scripts/fetchers/MastodonFetcher.js b/src/scripts/fetchers/MastodonFetcher.js index ef58f49..32fb9f3 100644 --- a/src/scripts/fetchers/MastodonFetcher.js +++ b/src/scripts/fetchers/MastodonFetcher.js @@ -3,6 +3,7 @@ import { Fetcher } from "./Fetcher.js"; export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; +const NUM_POSTS = 15; export class MastodonFetcher extends Fetcher { /** @@ -52,7 +53,7 @@ export class MastodonFetcher extends Fetcher { * @returns {Promise} - A promise that resolves to an array of posts for the given hashtag */ async #fetchPostsByHashtag(instURL, hashtag) { - const trendingPostURL = instURL + POST_SUFFIX + hashtag; + const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_POSTS; try { const response = await fetch(trendingPostURL); if (!response.ok) { From 1d03c1911b6a7059b59d9b5c7598c9371236cece Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 13 Dec 2023 01:30:28 +0000 Subject: [PATCH 2/7] Generated documentation --- docs/Display.html | 2 +- docs/Fetcher.html | 2 +- docs/InstanceEntry.html | 2 +- docs/Paginator_Paginator.html | 2 +- docs/entity_InstanceEntry.js.html | 2 +- docs/fetchers_Fetcher.js.html | 2 +- docs/fetchers_LemmyFetcher.js.html | 2 +- docs/fetchers_MastodonFetcher.js.html | 5 +++-- docs/global.html | 2 +- docs/index.html | 2 +- docs/instanceList.js.html | 2 +- docs/pageBuilder.js.html | 2 +- docs/paginator.js.html | 2 +- docs/postBuilder_LemmyPostBuilder.js.html | 2 +- docs/postBuilder_MastodonPostBuilder.js.html | 2 +- docs/postBuilder_PostBuilder.js.html | 2 +- 16 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/Display.html b/docs/Display.html index fa15717..05d0445 100644 --- a/docs/Display.html +++ b/docs/Display.html @@ -121,7 +121,7 @@

Home

Classes

  • diff --git a/docs/Fetcher.html b/docs/Fetcher.html index d312c52..e6d7857 100644 --- a/docs/Fetcher.html +++ b/docs/Fetcher.html @@ -121,7 +121,7 @@

    Home

    Classes

    • diff --git a/docs/InstanceEntry.html b/docs/InstanceEntry.html index c39e076..7cf1686 100644 --- a/docs/InstanceEntry.html +++ b/docs/InstanceEntry.html @@ -168,7 +168,7 @@

      Home

      Classes

      • diff --git a/docs/Paginator_Paginator.html b/docs/Paginator_Paginator.html index 8a2e0fc..6665253 100644 --- a/docs/Paginator_Paginator.html +++ b/docs/Paginator_Paginator.html @@ -229,7 +229,7 @@

        Home

        Classes

        • diff --git a/docs/entity_InstanceEntry.js.html b/docs/entity_InstanceEntry.js.html index f1fadad..5f1e882 100644 --- a/docs/entity_InstanceEntry.js.html +++ b/docs/entity_InstanceEntry.js.html @@ -111,7 +111,7 @@

          Home

          Classes

          • diff --git a/docs/fetchers_Fetcher.js.html b/docs/fetchers_Fetcher.js.html index 27c6160..d29561a 100644 --- a/docs/fetchers_Fetcher.js.html +++ b/docs/fetchers_Fetcher.js.html @@ -54,7 +54,7 @@

            Home

            Classes

            • diff --git a/docs/fetchers_LemmyFetcher.js.html b/docs/fetchers_LemmyFetcher.js.html index f867b14..b2d3b44 100644 --- a/docs/fetchers_LemmyFetcher.js.html +++ b/docs/fetchers_LemmyFetcher.js.html @@ -74,7 +74,7 @@

              Home

              Classes

              • diff --git a/docs/fetchers_MastodonFetcher.js.html b/docs/fetchers_MastodonFetcher.js.html index 3e6eec1..38d3d01 100644 --- a/docs/fetchers_MastodonFetcher.js.html +++ b/docs/fetchers_MastodonFetcher.js.html @@ -31,6 +31,7 @@

                Source: fetchers/MastodonFetcher.js

                export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; +const NUM_POSTS = 15; export class MastodonFetcher extends Fetcher { /** @@ -80,7 +81,7 @@

                Source: fetchers/MastodonFetcher.js

                * @returns {Promise<Array>} - A promise that resolves to an array of posts for the given hashtag */ async #fetchPostsByHashtag(instURL, hashtag) { - const trendingPostURL = instURL + POST_SUFFIX + hashtag; + const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_POSTS; try { const response = await fetch(trendingPostURL); if (!response.ok) { @@ -110,7 +111,7 @@

                Home

                Classes

                • diff --git a/docs/global.html b/docs/global.html index e31b513..60aca8d 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1370,7 +1370,7 @@

                  Home

                  Classes

                  • diff --git a/docs/index.html b/docs/index.html index 3203ca9..f72211e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,7 +56,7 @@

                    Home

                    Classes

                    • diff --git a/docs/instanceList.js.html b/docs/instanceList.js.html index 54976fb..204d507 100644 --- a/docs/instanceList.js.html +++ b/docs/instanceList.js.html @@ -150,7 +150,7 @@

                      Home

                      Classes

                      • diff --git a/docs/pageBuilder.js.html b/docs/pageBuilder.js.html index 7b65be4..f6e4ee5 100644 --- a/docs/pageBuilder.js.html +++ b/docs/pageBuilder.js.html @@ -101,7 +101,7 @@

                        Home

                        Classes

                        • diff --git a/docs/paginator.js.html b/docs/paginator.js.html index b39ea68..2a3396e 100644 --- a/docs/paginator.js.html +++ b/docs/paginator.js.html @@ -128,7 +128,7 @@

                          Home

                          Classes

                          • diff --git a/docs/postBuilder_LemmyPostBuilder.js.html b/docs/postBuilder_LemmyPostBuilder.js.html index 7a22ae7..dcbcac0 100644 --- a/docs/postBuilder_LemmyPostBuilder.js.html +++ b/docs/postBuilder_LemmyPostBuilder.js.html @@ -105,7 +105,7 @@

                            Home

                            Classes

                            • diff --git a/docs/postBuilder_MastodonPostBuilder.js.html b/docs/postBuilder_MastodonPostBuilder.js.html index b372a61..68bf4a4 100644 --- a/docs/postBuilder_MastodonPostBuilder.js.html +++ b/docs/postBuilder_MastodonPostBuilder.js.html @@ -78,7 +78,7 @@

                              Home

                              Classes

                              • diff --git a/docs/postBuilder_PostBuilder.js.html b/docs/postBuilder_PostBuilder.js.html index 8283290..c876972 100644 --- a/docs/postBuilder_PostBuilder.js.html +++ b/docs/postBuilder_PostBuilder.js.html @@ -57,7 +57,7 @@

                                Home

                                Classes

                                • From 7730c7df4bc73ace1b5009f33e68f25982aa2bcb Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 13 Dec 2023 01:38:08 +0000 Subject: [PATCH 3/7] Generated documentation --- docs/Display.html | 2 +- docs/Fetcher.html | 2 +- docs/InstanceEntry.html | 2 +- docs/Paginator_Paginator.html | 2 +- docs/entity_InstanceEntry.js.html | 2 +- docs/fetchers_Fetcher.js.html | 2 +- docs/fetchers_LemmyFetcher.js.html | 2 +- docs/fetchers_MastodonFetcher.js.html | 2 +- docs/global.html | 2 +- docs/index.html | 2 +- docs/instanceList.js.html | 2 +- docs/pageBuilder.js.html | 2 +- docs/paginator.js.html | 2 +- docs/postBuilder_LemmyPostBuilder.js.html | 2 +- docs/postBuilder_MastodonPostBuilder.js.html | 2 +- docs/postBuilder_PostBuilder.js.html | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/Display.html b/docs/Display.html index ef85c04..d3a52ce 100644 --- a/docs/Display.html +++ b/docs/Display.html @@ -121,7 +121,7 @@

                                  Home

                                  Classes

                                  • diff --git a/docs/Fetcher.html b/docs/Fetcher.html index 62c01ac..456ab05 100644 --- a/docs/Fetcher.html +++ b/docs/Fetcher.html @@ -121,7 +121,7 @@

                                    Home

                                    Classes

                                    • diff --git a/docs/InstanceEntry.html b/docs/InstanceEntry.html index 4f13e14..30c03bd 100644 --- a/docs/InstanceEntry.html +++ b/docs/InstanceEntry.html @@ -168,7 +168,7 @@

                                      Home

                                      Classes

                                      • diff --git a/docs/Paginator_Paginator.html b/docs/Paginator_Paginator.html index af6b699..eb6f397 100644 --- a/docs/Paginator_Paginator.html +++ b/docs/Paginator_Paginator.html @@ -229,7 +229,7 @@

                                        Home

                                        Classes

                                        • diff --git a/docs/entity_InstanceEntry.js.html b/docs/entity_InstanceEntry.js.html index 7485e03..a688911 100644 --- a/docs/entity_InstanceEntry.js.html +++ b/docs/entity_InstanceEntry.js.html @@ -111,7 +111,7 @@

                                          Home

                                          Classes

                                          • diff --git a/docs/fetchers_Fetcher.js.html b/docs/fetchers_Fetcher.js.html index 770d889..44a5784 100644 --- a/docs/fetchers_Fetcher.js.html +++ b/docs/fetchers_Fetcher.js.html @@ -54,7 +54,7 @@

                                            Home

                                            Classes

                                            • diff --git a/docs/fetchers_LemmyFetcher.js.html b/docs/fetchers_LemmyFetcher.js.html index 9dd4253..d232bdb 100644 --- a/docs/fetchers_LemmyFetcher.js.html +++ b/docs/fetchers_LemmyFetcher.js.html @@ -73,7 +73,7 @@

                                              Home

                                              Classes

                                              • diff --git a/docs/fetchers_MastodonFetcher.js.html b/docs/fetchers_MastodonFetcher.js.html index a75a6be..3700507 100644 --- a/docs/fetchers_MastodonFetcher.js.html +++ b/docs/fetchers_MastodonFetcher.js.html @@ -110,7 +110,7 @@

                                                Home

                                                Classes

                                                • diff --git a/docs/global.html b/docs/global.html index bf82b88..0c43572 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1370,7 +1370,7 @@

                                                  Home

                                                  Classes

                                                  • diff --git a/docs/index.html b/docs/index.html index 08fab78..d6cc88e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,7 +56,7 @@

                                                    Home

                                                    Classes

                                                    • diff --git a/docs/instanceList.js.html b/docs/instanceList.js.html index d6a3cd1..f67fa51 100644 --- a/docs/instanceList.js.html +++ b/docs/instanceList.js.html @@ -150,7 +150,7 @@

                                                      Home

                                                      Classes

                                                      • diff --git a/docs/pageBuilder.js.html b/docs/pageBuilder.js.html index 85b75cd..4f8a3b9 100644 --- a/docs/pageBuilder.js.html +++ b/docs/pageBuilder.js.html @@ -101,7 +101,7 @@

                                                        Home

                                                        Classes

                                                        • diff --git a/docs/paginator.js.html b/docs/paginator.js.html index 8a2a92f..b070c35 100644 --- a/docs/paginator.js.html +++ b/docs/paginator.js.html @@ -125,7 +125,7 @@

                                                          Home

                                                          Classes

                                                          • diff --git a/docs/postBuilder_LemmyPostBuilder.js.html b/docs/postBuilder_LemmyPostBuilder.js.html index e532ef7..477668c 100644 --- a/docs/postBuilder_LemmyPostBuilder.js.html +++ b/docs/postBuilder_LemmyPostBuilder.js.html @@ -105,7 +105,7 @@

                                                            Home

                                                            Classes

                                                            • diff --git a/docs/postBuilder_MastodonPostBuilder.js.html b/docs/postBuilder_MastodonPostBuilder.js.html index 56a920a..782759d 100644 --- a/docs/postBuilder_MastodonPostBuilder.js.html +++ b/docs/postBuilder_MastodonPostBuilder.js.html @@ -78,7 +78,7 @@

                                                              Home

                                                              Classes

                                                              • diff --git a/docs/postBuilder_PostBuilder.js.html b/docs/postBuilder_PostBuilder.js.html index 86fb436..f961918 100644 --- a/docs/postBuilder_PostBuilder.js.html +++ b/docs/postBuilder_PostBuilder.js.html @@ -57,7 +57,7 @@

                                                                Home

                                                                Classes

                                                                • From 00b384eb3719524f9f4a02fd864135bd540a01f8 Mon Sep 17 00:00:00 2001 From: Shrivaths Shyam Date: Tue, 12 Dec 2023 19:08:55 -0800 Subject: [PATCH 4/7] fix testing --- src/scripts/fetchers/MastodonFetcher.js | 4 ++-- test/scripts/fetchers/MastodonFetcher.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scripts/fetchers/MastodonFetcher.js b/src/scripts/fetchers/MastodonFetcher.js index 896b882..144d3de 100644 --- a/src/scripts/fetchers/MastodonFetcher.js +++ b/src/scripts/fetchers/MastodonFetcher.js @@ -2,7 +2,7 @@ import { Fetcher } from "./Fetcher.js"; export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; -const NUM_POSTS = 15; +export const NUM_MASTODON_POSTS = 20; export class MastodonFetcher extends Fetcher { /** @@ -52,7 +52,7 @@ export class MastodonFetcher extends Fetcher { * @returns {Promise} - A promise that resolves to an array of posts for the given hashtag */ async #fetchPostsByHashtag(instURL, hashtag) { - const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_POSTS; + const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_MASTODON_POSTS; try { const response = await fetch(trendingPostURL); if (!response.ok) { diff --git a/test/scripts/fetchers/MastodonFetcher.test.js b/test/scripts/fetchers/MastodonFetcher.test.js index f6dc9e8..0c102cf 100644 --- a/test/scripts/fetchers/MastodonFetcher.test.js +++ b/test/scripts/fetchers/MastodonFetcher.test.js @@ -1,6 +1,6 @@ import { describe, it, beforeEach } from "node:test"; import * as assert from "assert"; -import { MastodonFetcher, TAGS_SUFFIX, POST_SUFFIX } from "../../../src/scripts/fetchers/MastodonFetcher.js"; +import { MastodonFetcher, TAGS_SUFFIX, POST_SUFFIX, NUM_MASTODON_POSTS } from "../../../src/scripts/fetchers/MastodonFetcher.js"; import sinon from "sinon"; const FAKE_URL = "fakeTrendingURL"; @@ -39,8 +39,8 @@ describe("MastodonFetcher", () => { }; // Mock trending post response for each tag - fetchStub.withArgs(FAKE_URL + POST_SUFFIX + "tag1").resolves(mockResponse); - fetchStub.withArgs(FAKE_URL + POST_SUFFIX + "tag2").resolves(mockResponse); + fetchStub.withArgs(FAKE_URL + POST_SUFFIX + "tag1" + "?limit=" + NUM_MASTODON_POSTS).resolves(mockResponse); + fetchStub.withArgs(FAKE_URL + POST_SUFFIX + "tag2" + "?limit=" + NUM_MASTODON_POSTS).resolves(mockResponse); const posts = await mastodonFetcher.fetchPosts(FAKE_URL); From 60547fc02157e740934608aab3e43489ed0ba1aa Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 13 Dec 2023 03:09:26 +0000 Subject: [PATCH 5/7] Generated documentation --- docs/Display.html | 2 +- docs/Fetcher.html | 2 +- docs/InstanceEntry.html | 2 +- docs/Paginator_Paginator.html | 2 +- docs/entity_InstanceEntry.js.html | 2 +- docs/fetchers_Fetcher.js.html | 2 +- docs/fetchers_LemmyFetcher.js.html | 2 +- docs/fetchers_MastodonFetcher.js.html | 6 +++--- docs/global.html | 2 +- docs/index.html | 2 +- docs/instanceList.js.html | 2 +- docs/pageBuilder.js.html | 2 +- docs/paginator.js.html | 2 +- docs/postBuilder_LemmyPostBuilder.js.html | 2 +- docs/postBuilder_MastodonPostBuilder.js.html | 2 +- docs/postBuilder_PostBuilder.js.html | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/Display.html b/docs/Display.html index d3a52ce..b254519 100644 --- a/docs/Display.html +++ b/docs/Display.html @@ -121,7 +121,7 @@

                                                                  Home

                                                                  Classes

                                                                  • diff --git a/docs/Fetcher.html b/docs/Fetcher.html index 456ab05..3e3d05c 100644 --- a/docs/Fetcher.html +++ b/docs/Fetcher.html @@ -121,7 +121,7 @@

                                                                    Home

                                                                    Classes

                                                                    • diff --git a/docs/InstanceEntry.html b/docs/InstanceEntry.html index 30c03bd..af66347 100644 --- a/docs/InstanceEntry.html +++ b/docs/InstanceEntry.html @@ -168,7 +168,7 @@

                                                                      Home

                                                                      Classes

                                                                      • diff --git a/docs/Paginator_Paginator.html b/docs/Paginator_Paginator.html index eb6f397..6534496 100644 --- a/docs/Paginator_Paginator.html +++ b/docs/Paginator_Paginator.html @@ -229,7 +229,7 @@

                                                                        Home

                                                                        Classes

                                                                        • diff --git a/docs/entity_InstanceEntry.js.html b/docs/entity_InstanceEntry.js.html index a688911..898a65c 100644 --- a/docs/entity_InstanceEntry.js.html +++ b/docs/entity_InstanceEntry.js.html @@ -111,7 +111,7 @@

                                                                          Home

                                                                          Classes

                                                                          • diff --git a/docs/fetchers_Fetcher.js.html b/docs/fetchers_Fetcher.js.html index 44a5784..62a6946 100644 --- a/docs/fetchers_Fetcher.js.html +++ b/docs/fetchers_Fetcher.js.html @@ -54,7 +54,7 @@

                                                                            Home

                                                                            Classes

                                                                            • diff --git a/docs/fetchers_LemmyFetcher.js.html b/docs/fetchers_LemmyFetcher.js.html index d232bdb..56e22be 100644 --- a/docs/fetchers_LemmyFetcher.js.html +++ b/docs/fetchers_LemmyFetcher.js.html @@ -73,7 +73,7 @@

                                                                              Home

                                                                              Classes

                                                                              • diff --git a/docs/fetchers_MastodonFetcher.js.html b/docs/fetchers_MastodonFetcher.js.html index 3700507..138baea 100644 --- a/docs/fetchers_MastodonFetcher.js.html +++ b/docs/fetchers_MastodonFetcher.js.html @@ -30,7 +30,7 @@

                                                                                Source: fetchers/MastodonFetcher.js

                                                                                export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; -const NUM_POSTS = 15; +export const NUM_MASTODON_POSTS = 20; export class MastodonFetcher extends Fetcher { /** @@ -80,7 +80,7 @@

                                                                                Source: fetchers/MastodonFetcher.js

                                                                                * @returns {Promise<Array>} - A promise that resolves to an array of posts for the given hashtag */ async #fetchPostsByHashtag(instURL, hashtag) { - const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_POSTS; + const trendingPostURL = instURL + POST_SUFFIX + hashtag + "?limit=" + NUM_MASTODON_POSTS; try { const response = await fetch(trendingPostURL); if (!response.ok) { @@ -110,7 +110,7 @@

                                                                                Home

                                                                                Classes

                                                                                • diff --git a/docs/global.html b/docs/global.html index 0c43572..d436caa 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1370,7 +1370,7 @@

                                                                                  Home

                                                                                  Classes

                                                                                  • diff --git a/docs/index.html b/docs/index.html index d6cc88e..8a50172 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,7 +56,7 @@

                                                                                    Home

                                                                                    Classes

                                                                                    • diff --git a/docs/instanceList.js.html b/docs/instanceList.js.html index f67fa51..5f43c07 100644 --- a/docs/instanceList.js.html +++ b/docs/instanceList.js.html @@ -150,7 +150,7 @@

                                                                                      Home

                                                                                      Classes

                                                                                      • diff --git a/docs/pageBuilder.js.html b/docs/pageBuilder.js.html index 4f8a3b9..4774ac0 100644 --- a/docs/pageBuilder.js.html +++ b/docs/pageBuilder.js.html @@ -101,7 +101,7 @@

                                                                                        Home

                                                                                        Classes

                                                                                        • diff --git a/docs/paginator.js.html b/docs/paginator.js.html index b070c35..96bfdb4 100644 --- a/docs/paginator.js.html +++ b/docs/paginator.js.html @@ -125,7 +125,7 @@

                                                                                          Home

                                                                                          Classes

                                                                                          • diff --git a/docs/postBuilder_LemmyPostBuilder.js.html b/docs/postBuilder_LemmyPostBuilder.js.html index 477668c..0382535 100644 --- a/docs/postBuilder_LemmyPostBuilder.js.html +++ b/docs/postBuilder_LemmyPostBuilder.js.html @@ -105,7 +105,7 @@

                                                                                            Home

                                                                                            Classes

                                                                                            • diff --git a/docs/postBuilder_MastodonPostBuilder.js.html b/docs/postBuilder_MastodonPostBuilder.js.html index 782759d..d857263 100644 --- a/docs/postBuilder_MastodonPostBuilder.js.html +++ b/docs/postBuilder_MastodonPostBuilder.js.html @@ -78,7 +78,7 @@

                                                                                              Home

                                                                                              Classes

                                                                                              • diff --git a/docs/postBuilder_PostBuilder.js.html b/docs/postBuilder_PostBuilder.js.html index f961918..b86e372 100644 --- a/docs/postBuilder_PostBuilder.js.html +++ b/docs/postBuilder_PostBuilder.js.html @@ -57,7 +57,7 @@

                                                                                                Home

                                                                                                Classes

                                                                                                • From c70d64a42889e9a4361e609fe615589f9b8105d7 Mon Sep 17 00:00:00 2001 From: Shrivaths Shyam Date: Tue, 12 Dec 2023 19:39:29 -0800 Subject: [PATCH 6/7] parallelize the mastodon fetching and limiting the number of mastodon posts per tag --- src/scripts/fetchers/MastodonFetcher.js | 12 +++++------- test/scripts/fetchers/MastodonFetcher.test.js | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/scripts/fetchers/MastodonFetcher.js b/src/scripts/fetchers/MastodonFetcher.js index 144d3de..aad3af4 100644 --- a/src/scripts/fetchers/MastodonFetcher.js +++ b/src/scripts/fetchers/MastodonFetcher.js @@ -2,7 +2,7 @@ import { Fetcher } from "./Fetcher.js"; export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; -export const NUM_MASTODON_POSTS = 20; +export const NUM_MASTODON_POSTS = 15; export class MastodonFetcher extends Fetcher { /** @@ -12,12 +12,10 @@ export class MastodonFetcher extends Fetcher { async fetchPosts(instURL) { try { const hashtags = await this.#fetchTrendingTags(instURL + TAGS_SUFFIX); - const posts = []; - for (const tag of hashtags) { - console.log("Fetching posts for tag: " + tag.name); - let response = await this.#fetchPostsByHashtag(instURL, tag.name); - posts.push(...response); - } + const fetchPromises = hashtags.map(tag => this.#fetchPostsByHashtag(instURL, tag.name)); + const responses = await Promise.all(fetchPromises); + const posts = responses.flat(); + posts.push(...posts); return posts; } catch (error) { diff --git a/test/scripts/fetchers/MastodonFetcher.test.js b/test/scripts/fetchers/MastodonFetcher.test.js index 0c102cf..47b9ec3 100644 --- a/test/scripts/fetchers/MastodonFetcher.test.js +++ b/test/scripts/fetchers/MastodonFetcher.test.js @@ -44,7 +44,7 @@ describe("MastodonFetcher", () => { const posts = await mastodonFetcher.fetchPosts(FAKE_URL); - assert.strictEqual(posts.length, 2); + assert.strictEqual(posts.length, 4); }); }); }); From 8915cdbf8035d7d929fcf3b645f1d186b555ac15 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 13 Dec 2023 03:40:25 +0000 Subject: [PATCH 7/7] Generated documentation --- docs/Display.html | 2 +- docs/Fetcher.html | 2 +- docs/InstanceEntry.html | 2 +- docs/Paginator_Paginator.html | 2 +- docs/entity_InstanceEntry.js.html | 2 +- docs/fetchers_Fetcher.js.html | 2 +- docs/fetchers_LemmyFetcher.js.html | 2 +- docs/fetchers_MastodonFetcher.js.html | 14 ++++++-------- docs/global.html | 2 +- docs/index.html | 2 +- docs/instanceList.js.html | 2 +- docs/pageBuilder.js.html | 2 +- docs/paginator.js.html | 2 +- docs/postBuilder_LemmyPostBuilder.js.html | 2 +- docs/postBuilder_MastodonPostBuilder.js.html | 2 +- docs/postBuilder_PostBuilder.js.html | 2 +- 16 files changed, 21 insertions(+), 23 deletions(-) diff --git a/docs/Display.html b/docs/Display.html index b254519..1c6d9a8 100644 --- a/docs/Display.html +++ b/docs/Display.html @@ -121,7 +121,7 @@

                                                                                                  Home

                                                                                                  Classes

                                                                                                  • diff --git a/docs/Fetcher.html b/docs/Fetcher.html index 3e3d05c..15c8976 100644 --- a/docs/Fetcher.html +++ b/docs/Fetcher.html @@ -121,7 +121,7 @@

                                                                                                    Home

                                                                                                    Classes

                                                                                                    • diff --git a/docs/InstanceEntry.html b/docs/InstanceEntry.html index af66347..b33f8f2 100644 --- a/docs/InstanceEntry.html +++ b/docs/InstanceEntry.html @@ -168,7 +168,7 @@

                                                                                                      Home

                                                                                                      Classes

                                                                                                      • diff --git a/docs/Paginator_Paginator.html b/docs/Paginator_Paginator.html index 6534496..aac09f6 100644 --- a/docs/Paginator_Paginator.html +++ b/docs/Paginator_Paginator.html @@ -229,7 +229,7 @@

                                                                                                        Home

                                                                                                        Classes

                                                                                                        • diff --git a/docs/entity_InstanceEntry.js.html b/docs/entity_InstanceEntry.js.html index 898a65c..c8ea19b 100644 --- a/docs/entity_InstanceEntry.js.html +++ b/docs/entity_InstanceEntry.js.html @@ -111,7 +111,7 @@

                                                                                                          Home

                                                                                                          Classes

                                                                                                          • diff --git a/docs/fetchers_Fetcher.js.html b/docs/fetchers_Fetcher.js.html index 62a6946..5cddf26 100644 --- a/docs/fetchers_Fetcher.js.html +++ b/docs/fetchers_Fetcher.js.html @@ -54,7 +54,7 @@

                                                                                                            Home

                                                                                                            Classes

                                                                                                            • diff --git a/docs/fetchers_LemmyFetcher.js.html b/docs/fetchers_LemmyFetcher.js.html index 56e22be..65b3ec0 100644 --- a/docs/fetchers_LemmyFetcher.js.html +++ b/docs/fetchers_LemmyFetcher.js.html @@ -73,7 +73,7 @@

                                                                                                              Home

                                                                                                              Classes

                                                                                                              • diff --git a/docs/fetchers_MastodonFetcher.js.html b/docs/fetchers_MastodonFetcher.js.html index 138baea..bf1ec08 100644 --- a/docs/fetchers_MastodonFetcher.js.html +++ b/docs/fetchers_MastodonFetcher.js.html @@ -30,7 +30,7 @@

                                                                                                                Source: fetchers/MastodonFetcher.js

                                                                                                                export const TAGS_SUFFIX = "/api/v1/trends/tags"; export const POST_SUFFIX = "/api/v1/timelines/tag/:"; -export const NUM_MASTODON_POSTS = 20; +export const NUM_MASTODON_POSTS = 15; export class MastodonFetcher extends Fetcher { /** @@ -40,12 +40,10 @@

                                                                                                                Source: fetchers/MastodonFetcher.js

                                                                                                                async fetchPosts(instURL) { try { const hashtags = await this.#fetchTrendingTags(instURL + TAGS_SUFFIX); - const posts = []; - for (const tag of hashtags) { - console.log("Fetching posts for tag: " + tag.name); - let response = await this.#fetchPostsByHashtag(instURL, tag.name); - posts.push(...response); - } + const fetchPromises = hashtags.map(tag => this.#fetchPostsByHashtag(instURL, tag.name)); + const responses = await Promise.all(fetchPromises); + const posts = responses.flat(); + posts.push(...posts); return posts; } catch (error) { @@ -110,7 +108,7 @@

                                                                                                                Home

                                                                                                                Classes

                                                                                                                • diff --git a/docs/global.html b/docs/global.html index d436caa..a24bd15 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1370,7 +1370,7 @@

                                                                                                                  Home

                                                                                                                  Classes

                                                                                                                  • diff --git a/docs/index.html b/docs/index.html index 8a50172..fbcbf25 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,7 +56,7 @@

                                                                                                                    Home

                                                                                                                    Classes

                                                                                                                    • diff --git a/docs/instanceList.js.html b/docs/instanceList.js.html index 5f43c07..112acee 100644 --- a/docs/instanceList.js.html +++ b/docs/instanceList.js.html @@ -150,7 +150,7 @@

                                                                                                                      Home

                                                                                                                      Classes

                                                                                                                      • diff --git a/docs/pageBuilder.js.html b/docs/pageBuilder.js.html index 4774ac0..6f68ef2 100644 --- a/docs/pageBuilder.js.html +++ b/docs/pageBuilder.js.html @@ -101,7 +101,7 @@

                                                                                                                        Home

                                                                                                                        Classes

                                                                                                                        • diff --git a/docs/paginator.js.html b/docs/paginator.js.html index 96bfdb4..836f893 100644 --- a/docs/paginator.js.html +++ b/docs/paginator.js.html @@ -125,7 +125,7 @@

                                                                                                                          Home

                                                                                                                          Classes

                                                                                                                          • diff --git a/docs/postBuilder_LemmyPostBuilder.js.html b/docs/postBuilder_LemmyPostBuilder.js.html index 0382535..8302c21 100644 --- a/docs/postBuilder_LemmyPostBuilder.js.html +++ b/docs/postBuilder_LemmyPostBuilder.js.html @@ -105,7 +105,7 @@

                                                                                                                            Home

                                                                                                                            Classes

                                                                                                                            • diff --git a/docs/postBuilder_MastodonPostBuilder.js.html b/docs/postBuilder_MastodonPostBuilder.js.html index d857263..15e4aef 100644 --- a/docs/postBuilder_MastodonPostBuilder.js.html +++ b/docs/postBuilder_MastodonPostBuilder.js.html @@ -78,7 +78,7 @@

                                                                                                                              Home

                                                                                                                              Classes

                                                                                                                              • diff --git a/docs/postBuilder_PostBuilder.js.html b/docs/postBuilder_PostBuilder.js.html index b86e372..78c50c5 100644 --- a/docs/postBuilder_PostBuilder.js.html +++ b/docs/postBuilder_PostBuilder.js.html @@ -57,7 +57,7 @@

                                                                                                                                Home

                                                                                                                                Classes