mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-16 13:55:51 -07:00
perf(stats): calculate vocabulary totals off main thread
This commit is contained in:
@@ -17,14 +17,10 @@ export function useVocabulary() {
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setSummary(null);
|
||||
const client = getStatsClient();
|
||||
Promise.allSettled([
|
||||
client.getVocabulary(500),
|
||||
client.getKanji(200),
|
||||
client.getKnownWords(),
|
||||
client.getVocabularySummary(),
|
||||
])
|
||||
.then(([wordsResult, kanjiResult, knownResult, summaryResult]) => {
|
||||
Promise.allSettled([client.getVocabulary(500), client.getKanji(200), client.getKnownWords()])
|
||||
.then(([wordsResult, kanjiResult, knownResult]) => {
|
||||
if (cancelled) return;
|
||||
const errors: string[] = [];
|
||||
|
||||
@@ -44,12 +40,6 @@ export function useVocabulary() {
|
||||
setKnownWords(new Set(knownResult.value));
|
||||
}
|
||||
|
||||
if (summaryResult.status === 'fulfilled') {
|
||||
setSummary(summaryResult.value);
|
||||
} else {
|
||||
errors.push(summaryResult.reason.message);
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
setError(errors.join('; '));
|
||||
}
|
||||
@@ -58,6 +48,14 @@ export function useVocabulary() {
|
||||
if (cancelled) return;
|
||||
setLoading(false);
|
||||
});
|
||||
void client
|
||||
.getVocabularySummary()
|
||||
.then((nextSummary) => {
|
||||
if (!cancelled) setSummary(nextSummary);
|
||||
})
|
||||
.catch((summaryError: unknown) => {
|
||||
console.error('Failed to load vocabulary summary', summaryError);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user