fix: prevent concurrent start() calls in readingProgressController

Added isLoading flag to block multiple start() calls from running in parallel.
The repeated start() calls were all waiting on queryEvents() calls,
creating a thundering herd that prevented any from completing.

Now only one start() runs at a time, and concurrent calls are skipped
with a console log.
This commit is contained in:
Gigi
2025-10-20 00:18:23 +02:00
parent a0829e834f
commit e8e629f4e1
3 changed files with 30 additions and 250 deletions

View File

@@ -30,6 +30,7 @@ class ReadingProgressController {
private lastLoadedPubkey: string | null = null
private generation = 0
private timelineSubscription: { unsubscribe: () => void } | null = null
private isLoading = false
onProgress(cb: ProgressMapCallback): () => void {
this.progressListeners.push(cb)
@@ -185,7 +186,14 @@ class ReadingProgressController {
return
}
// Prevent concurrent starts
if (this.isLoading) {
console.log('[readingProgress] Already loading, skipping concurrent start')
return
}
this.setLoading(true)
this.isLoading = true
try {
// Seed from local cache immediately (survives refresh/flight mode)
@@ -261,7 +269,7 @@ class ReadingProgressController {
}
// Process mark-as-read reactions
;[...kind17Events].forEach((evt) => {
[...kind17Events].forEach((evt) => {
if (evt.content === MARK_AS_READ_EMOJI) {
// For kind:17, the URL is in the #r tag
const rTag = evt.tags.find(t => t[0] === 'r')?.[1]
@@ -340,6 +348,7 @@ class ReadingProgressController {
} finally {
if (startGeneration === this.generation) {
this.setLoading(false)
this.isLoading = false
}
// Debug: Show what we have
console.log('[readingProgress] === FINAL STATE ===')