Skip to content

Commit eb40c8a

Browse files
committed
Merge pull request #26 from jsonMartin/revert-21-readwise-throttling
Revert "feat: 👽 implement readwise throttling"
2 parents df90f30 + 3f14868 commit eb40c8a

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changelog
2-
## 1.3.1 (2023-08-18)
2+
## 1.4.0 (2023-08-18)
33
Thanks to @johannrichard for the following contributions:
44

55
### Features
@@ -10,7 +10,6 @@ Thanks to @johannrichard for the following contributions:
1010
- The colon in a title is a special character which by default is replaced witha a dash (-) in filenames. With this change, users can choose what string to use as a replacement.
1111

1212
### Updates
13-
- Implement improved readwise API throttling
1413
- Change field names to reflect their use in frontmatter
1514
- Introduce option for quotes in tag format
1615
- make tag formatting more flexible

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"id": "readwise-mirror",
33
"name": "Readwise Mirror",
4-
"version": "1.3.1",
4+
"version": "1.4.0",
55
"minAppVersion": "0.11.0",
66
"description": "Mirror your Readwise library directly to an Obsidian vault",
77
"author": "jsonmartin",
88
"authorUrl": "https://github.com/jsonMartin/",
99
"isDesktopOnly": false
10-
}
10+
}

readwiseApi.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,10 @@ export class ReadwiseApi {
109109

110110
if (response.status === 429) {
111111
// Error handling for rate limit throttling
112-
// b/c of limitations with cross-origin requests, we don't have (easy) access to the header
113-
// We must therefore extract the seconds from the statusText:
114-
// "Request was throttled. Expected available in 39 seconds."
115-
116-
let rateLimitedDelayTime: number = 4000; // Base throttling, 20 requests per minute are the maximum allowable
117-
118-
if (data.detail) {
119-
console.log(`Readwise: ${data.detail}`);
120-
const rate = data.detail.match(/available\sin\s([0-9]+)\sseconds/);
121-
if (rate) {
122-
rateLimitedDelayTime = parseInt(rate[1]) * 1000 + 1000;
123-
}
124-
}
125-
112+
const rateLimitedDelayTime = parseInt(response.headers.get('Retry-After')) * 1000 + 1000;
126113
console.warn(`Readwise: API Rate Limited, waiting to retry for ${rateLimitedDelayTime}`);
127114
this.notify.setStatusBarText(`Readwise: API Rate Limited, waiting ${rateLimitedDelayTime}`);
115+
128116
await new Promise((_) => setTimeout(_, rateLimitedDelayTime));
129117
console.info('Readwise: Trying to fetch highlights again...');
130118
this.notify.setStatusBarText(`Readwise: Attempting to retry...`);
@@ -142,8 +130,7 @@ export class ReadwiseApi {
142130
}
143131
} while (data.next);
144132

145-
if (results.length > 0)
146-
console.info(`Readwise: Processed ${results.length} total ${contentType} results successfully`);
133+
if (results.length > 0) console.info(`Readwise: Processed ${results.length} total ${contentType} results successfully`);
147134
return results;
148135
}
149136

0 commit comments

Comments
 (0)