Skip to content

Commit a23ac41

Browse files
feildmasterclaude
andcommitted
fix: user api calls share a single deck config request
Calls made at the same time each waited on their own listener and then made their own request. Share one promise, use a once listener, and clear it again if the request fails. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent c75d46e commit a23ac41

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</extended>
1616
1. Added `plugin.settings().name(<string>)` to rename the first settings tab
1717
1. Fixed `plugin.events.once`, `until`, and `off` not removing listeners
18+
1. Fixed `underscript.user.getDecks()`, `getCollection()`, `getArtifacts()`, and `getAllArtifacts()` each making their own request when called at the same time
1819
1. Added `underscript.d.ts` to each release, so editors like VS Code can suggest and check your plugin code<extended>
1920
- This is optional, plugins work the same without it.
2021
- Download `underscript.d.ts` from the latest release and put it next to your plugin's script.

‎src/utils/user.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,24 @@ export function getAllArtifacts() { // TODO: This isn't really a "user" function
5353
return getDeckConfig().then(({ allArtifacts: data = [] }) => parse(data));
5454
}
5555

56+
let deckConfig;
5657
function getDeckConfig() {
57-
return new Promise((res) => {
58-
eventManager.on('Deck:Loaded', (data) => res(data));
59-
sleep(500).then(() => res());
60-
}).then((res) => {
61-
if (res) return res;
62-
return axios.get('DecksConfig').then(({ data }) => {
63-
eventManager.singleton.emit('Deck:Loaded', data);
64-
return data;
58+
if (!deckConfig) {
59+
deckConfig = new Promise((res) => {
60+
eventManager.once('Deck:Loaded', res);
61+
sleep(500).then(() => res());
62+
}).then((res) => {
63+
if (res) return res;
64+
return axios.get('DecksConfig').then(({ data }) => {
65+
eventManager.singleton.emit('Deck:Loaded', data);
66+
return data;
67+
});
68+
}).catch((err) => {
69+
deckConfig = undefined;
70+
throw err;
6571
});
66-
});
72+
}
73+
return deckConfig;
6774
}
6875

6976
function parse(data) {

0 commit comments

Comments
 (0)