refactor: disable account queue globally

Set accounts.disableQueue = true on AccountManager during initialization:
- Applies to all accounts automatically
- No need for temporary queue toggling in individual operations
- Makes all bunker requests instant (no internal queueing)

Removed temporary queue disabling from bookmarkProcessing.ts since
it's now globally disabled.

Updated Amber.md to document the global approach.

This eliminates the root cause of decrypt hangs - requests no longer
wait in an internal queue for previous requests to complete.
This commit is contained in:
Gigi
2025-10-17 21:19:21 +02:00
parent 0785b034e4
commit 8eaba04d91
7 changed files with 24 additions and 40 deletions

View File

@@ -189,6 +189,10 @@ function App() {
const store = new EventStore()
const accounts = new AccountManager()
// Disable request queueing globally - makes all operations instant
// Queue causes requests to wait for user interaction which blocks batch operations
accounts.disableQueue = true
// Register common account types (needed for deserialization)
registerCommonAccountTypes(accounts)

View File

@@ -203,13 +203,11 @@ const Debug: React.FC<DebugProps> = ({ relayPool }) => {
setLiveTiming(prev => ({ ...prev, loadBookmarks: { startTime: start } }))
// Use onEvent callback to stream events as they arrive
// Shorter timeouts for debug page - trust EOSE from fast relays
// Trust EOSE - completes when relays finish, no artificial timeouts
const rawEvents = await queryEvents(
relayPool,
{ kinds: [KINDS.ListSimple, KINDS.ListReplaceable, KINDS.List, KINDS.WebBookmark], authors: [activeAccount.pubkey] },
{
localTimeoutMs: 800, // Local relays should be instant
remoteTimeoutMs: 2000, // Trust EOSE from fast remote relays
onEvent: (evt) => {
// Add event immediately with live deduplication
setBookmarkEvents(prev => {

View File

@@ -189,21 +189,11 @@ export async function collectBookmarksFromEvents(
// Decrypt events sequentially
const privateItemsAll: IndividualBookmark[] = []
if (decryptJobs.length > 0 && signerCandidate) {
// Disable queueing for batch operations to avoid blocking on user interaction
const accountWithQueue = activeAccount as { disableQueue?: boolean }
const originalQueueState = accountWithQueue.disableQueue
accountWithQueue.disableQueue = true
try {
for (const job of decryptJobs) {
const privateItems = await decryptEvent(job.evt, activeAccount, signerCandidate, job.metadata)
if (privateItems && privateItems.length > 0) {
privateItemsAll.push(...privateItems)
}
for (const job of decryptJobs) {
const privateItems = await decryptEvent(job.evt, activeAccount, signerCandidate, job.metadata)
if (privateItems && privateItems.length > 0) {
privateItemsAll.push(...privateItems)
}
} finally {
// Restore original queue state
accountWithQueue.disableQueue = originalQueueState
}
}

View File

@@ -144,7 +144,7 @@ const { publicItemsAll, privateItemsAll, newestCreatedAt, latestContent, allTags
const events = await queryEvents(
relayPool,
{ ids: Array.from(new Set(noteIds)) },
{ localTimeoutMs: 800, remoteTimeoutMs: 2500 }
{}
)
events.forEach((e: NostrEvent) => {
idToEvent.set(e.id, e)
@@ -186,7 +186,7 @@ const { publicItemsAll, privateItemsAll, newestCreatedAt, latestContent, allTags
const events = await queryEvents(
relayPool,
{ kinds: [kind], authors, '#d': identifiers },
{ localTimeoutMs: 800, remoteTimeoutMs: 2500 }
{}
)
events.forEach((e: NostrEvent) => {

View File

@@ -1,7 +1,6 @@
import { RelayPool } from 'applesauce-relay'
import { prioritizeLocalRelays } from '../utils/helpers'
import { queryEvents } from './dataFetch'
import { CONTACTS_REMOTE_TIMEOUT_MS } from '../config/network'
/**
* Fetches the contact list (follows) for a specific user
@@ -24,7 +23,6 @@ export const fetchContacts = async (
{ kinds: [3], authors: [pubkey] },
{
relayUrls,
remoteTimeoutMs: CONTACTS_REMOTE_TIMEOUT_MS,
onEvent: (event: { created_at: number; tags: string[][] }) => {
// Stream partials as we see any contact list
for (const tag of event.tags) {

View File

@@ -1,20 +1,18 @@
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
import { Observable, merge, takeUntil, timer, toArray, tap, lastValueFrom } from 'rxjs'
import { Observable, merge, toArray, tap, lastValueFrom } from 'rxjs'
import { NostrEvent } from 'nostr-tools'
import { Filter } from 'nostr-tools/filter'
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
import { LOCAL_TIMEOUT_MS, REMOTE_TIMEOUT_MS } from '../config/network'
export interface QueryOptions {
relayUrls?: string[]
localTimeoutMs?: number
remoteTimeoutMs?: number
onEvent?: (event: NostrEvent) => void
}
/**
* Unified local-first query helper with optional streaming callback.
* Returns all collected events (deduped by id) after both streams complete or time out.
* Returns all collected events (deduped by id) after both streams complete (EOSE).
* Trusts relay EOSE signals - no artificial timeouts.
*/
export async function queryEvents(
relayPool: RelayPool,
@@ -23,8 +21,6 @@ export async function queryEvents(
): Promise<NostrEvent[]> {
const {
relayUrls,
localTimeoutMs = LOCAL_TIMEOUT_MS,
remoteTimeoutMs = REMOTE_TIMEOUT_MS,
onEvent
} = options
@@ -41,8 +37,7 @@ export async function queryEvents(
.pipe(
onlyEvents(),
onEvent ? tap((e: NostrEvent) => onEvent(e)) : tap(() => {}),
completeOnEose(),
takeUntil(timer(localTimeoutMs))
completeOnEose()
) as unknown as Observable<NostrEvent>
: new Observable<NostrEvent>((sub) => sub.complete())
@@ -52,8 +47,7 @@ export async function queryEvents(
.pipe(
onlyEvents(),
onEvent ? tap((e: NostrEvent) => onEvent(e)) : tap(() => {}),
completeOnEose(),
takeUntil(timer(remoteTimeoutMs))
completeOnEose()
) as unknown as Observable<NostrEvent>
: new Observable<NostrEvent>((sub) => sub.complete())