Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat Throttled List #7

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/IpfsPinSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,22 @@ export default class IpfsPinSync {

let pinsExistToCheck = true;
let pageCount = 0,
pageLimit = 250;
pageLimit = 1000;
let pinList = [];

const listLimiter = new Bottleneck({
reservoir: 25,
reservoirRefreshInterval: 60 * 1000,
reservoirRefreshAmount: 25,
maxConcurrent: 1
});
const throttledListPins = listLimiter.wrap(axios);

while (pinsExistToCheck === true) {
//Request Page of Pins from Provider
listConfig.params.pageLimit = pageLimit;
listConfig.params.pageOffset = pageCount * pageLimit;
const listRequest = await axios(listConfig);
const listRequest = await throttledListPins(listConfig);
for (let pin of listRequest.data.rows) {
pinList.push({
pin: {
Expand All @@ -133,8 +141,16 @@ export default class IpfsPinSync {
let earliestPinInList = null
let pinList = [];

const listLimiter = new Bottleneck({
reservoir: 25,
reservoirRefreshInterval: 10 * 1000,
reservoirRefreshAmount: 25,
maxConcurrent: 1
});
const throttledGetPins = listLimiter.wrap(client.pinsGet);

while (pinsExistToCheck === true) {
// Get 1000 Successful Pins
// Get 500 Successful Pins
let pinsGetOptions = {
limit: 500,
status: new Set([Status.Pinned, Status.Pinning, Status.Queued]) // requires a set, and not an array
Expand All @@ -143,7 +159,7 @@ export default class IpfsPinSync {
pinsGetOptions.before = earliestPinInList
}

const {count, results} = await client.pinsGet(pinsGetOptions)
const {count, results} = await throttledGetPins(pinsGetOptions)

console.log(count, results)
pinList = pinList.concat(Array.from(results));
Expand Down