Skip to content

Commit

Permalink
Update batch sizes due to Cloudfront
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Jan 1, 2025
1 parent 01223b7 commit 3a8c705
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ let PocketTagger = function (pocket, urlTagger) {
};

PocketTagger.prototype.fetchArticles = async function (count) {
count = count || 9999;
count = count || parseInt(process.env.POCKET_TAGGER_FETCH_COUNT, 10) || 500;

let articles = (await this.pocket.get({ count: count })).list;
let articles = (
await this.pocket.get({ count: count, state: "unread", sort: "newest" })
).list;
debug(`Found ${Object.keys(articles).length} articles`);

let reformatted = {};
Expand Down Expand Up @@ -97,17 +99,24 @@ PocketTagger.prototype.persistTags = async function (articles, tags) {
if (tagActions.length) {
debug("Sending tag updates");

const chunkSize = process.env.POCKET_TAGGER_TAGS_CHUNK_SIZE || 500;
const chunkSize =
parseInt(process.env.POCKET_TAGGER_TAGS_CHUNK_SIZE, 10) || 20;

const pocketUpdates = [];
for (let i = 0; i < tagActions.length; i += chunkSize) {
debug("Sending tag updates: Chunk #" + Math.floor(i / chunkSize));
const chunk = tagActions.slice(i, i + chunkSize);
pocketUpdates.push(
this.pocket.send({
if (process.env.POCKET_TAGGER_TAG_SYNCHRONOUS === "true") {
await this.pocket.send({
actions: chunk,
})
);
});
} else {
pocketUpdates.push(
this.pocket.send({
actions: chunk,
})
);
}
}

await Promise.all(pocketUpdates);
Expand Down
6 changes: 3 additions & 3 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ describe("PocketTagger", function () {
});

describe("#fetchArticles", async function () {
it("requests 9999 articles by default", async function () {
it("requests 500 articles by default", async function () {
const mock = this.sandbox.mock(Pocket.prototype, "get");
mock
.expects("get")
.once()
.withExactArgs({ count: 9999 })
.withExactArgs({ count: 500, state: "unread", sort: "newest" })
.returns({ list: [] });
await this.tagger.fetchArticles();
mock.verify();
Expand All @@ -147,7 +147,7 @@ describe("PocketTagger", function () {
mock
.expects("get")
.once()
.withExactArgs({ count: 10 })
.withExactArgs({ count: 10, state: "unread", sort: "newest" })
.returns({ list: [] });
await this.tagger.fetchArticles(10);
mock.verify();
Expand Down

0 comments on commit 3a8c705

Please sign in to comment.